From ddebbc0b7f45eaf07a2242fd91f1a92ee27099a9 Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Thu, 6 Sep 2018 20:28:04 +0200 Subject: Changing the vault trait to use Result<_, VaultError> more liberally --- lockchain-core/src/errors/vault.rs | 4 ++++ lockchain-core/src/init.rs | 3 ++- lockchain-core/src/traits.rs | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lockchain-core/src/errors/vault.rs b/lockchain-core/src/errors/vault.rs index bcfcd13..37d8662 100644 --- a/lockchain-core/src/errors/vault.rs +++ b/lockchain-core/src/errors/vault.rs @@ -5,6 +5,10 @@ use std::fmt::{Display, Formatter, Result}; #[derive(Debug, Serialize, Deserialize)] pub enum Error { + /// Indicates that **mandatory** fields in the + /// vault generator haven't been set – vault + /// constructor was never called. + IncompleteGenerator, /// A vault already exists with that path-id AlreadyExists, /// The provided path is invalid diff --git a/lockchain-core/src/init.rs b/lockchain-core/src/init.rs index f7f2d5d..bf40518 100644 --- a/lockchain-core/src/init.rs +++ b/lockchain-core/src/init.rs @@ -1,4 +1,5 @@ use traits::{Body, Vault}; +use errors::VaultError; /// Describes the internal permission layout of a vault pub enum VaultType { @@ -69,7 +70,7 @@ impl Generator { } /// Finally call this function to construct the vault - pub fn finalise(self) -> V + pub fn finalise(self) -> Result where V: Vault, B: Body, diff --git a/lockchain-core/src/traits.rs b/lockchain-core/src/traits.rs index efde578..13fc1b3 100644 --- a/lockchain-core/src/traits.rs +++ b/lockchain-core/src/traits.rs @@ -11,7 +11,8 @@ //! compilation work without external crates but not calling //! functions at runtime. -use initialise::Generator; +use errors::VaultError; +use init::Generator; use meta::{MetaDomain, VaultMetadata}; use record::{EncryptedBody, Header, Payload, Record}; use serde::{de::DeserializeOwned, Serialize}; @@ -123,9 +124,9 @@ where T: Body, { /// Consumes a vault generator to construct a vault - fn new(cfg: Generator) -> Self; + fn new(Generator) -> Result, VaultError>; /// Load and open an existing vault - fn load(name: &str, location: &str) -> Option>; + fn load(name: &str, location: &str) -> Result, VaultError>; /// Unlock the vault for a specific user fn authenticate(&mut self, username: &str, secret: &str) -> Token; /// End a specific user session -- cgit v1.2.3