diff options
author | Katharina Fey <kookie@spacekookie.de> | 2018-06-30 16:24:53 +0200 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2018-06-30 16:24:53 +0200 |
commit | b51525e65fed85293ac4ad82ceae03ef2eb7497a (patch) | |
tree | 6b3407d1f3290a3cbecb48b6bb6af41900127420 | |
parent | e20809885cb6c701e54bb67c21f31c9046102386 (diff) |
Ironing out some problems with the ApiState serialisation
-rw-r--r-- | lockchain-core/src/users.rs | 6 | ||||
-rw-r--r-- | lockchain-http/src/state.rs | 18 |
2 files changed, 6 insertions, 18 deletions
diff --git a/lockchain-core/src/users.rs b/lockchain-core/src/users.rs index 0d5973c..880c7f4 100644 --- a/lockchain-core/src/users.rs +++ b/lockchain-core/src/users.rs @@ -21,7 +21,7 @@ use std::collections::HashMap; use {meta::MetaDomain, traits::AutoEncoder}; /// Specifies access to a resource -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone)] pub enum Access { /// Allows specific access to an entire API Api, @@ -32,7 +32,7 @@ pub enum Access { } /// Specifies the capabilities of a user -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone)] pub enum Role { Reader, Editor, @@ -52,7 +52,7 @@ pub enum Role { /// changing the rules! /// /// An user can have multiple role-access pairs -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone)] pub struct User { name: String, pw_hash: String, diff --git a/lockchain-http/src/state.rs b/lockchain-http/src/state.rs index 78daf81..423e674 100644 --- a/lockchain-http/src/state.rs +++ b/lockchain-http/src/state.rs @@ -107,14 +107,8 @@ where { fn from(me: &'state ApiState<B, V>) -> Self { Self { - vaults: me - .vaults - .into_iter() - .fold(Vec::new(), |mut acc: Vec<String>, (k, v)| { - acc.push(k); - acc - }), - users: me.users.get_all().iter().map(|(_, v)| v).collect(), + vaults: me.vaults.iter().map(|(k, _)| k.clone()).collect(), + users: me.users.get_all().iter().map(|(_, v)| v.clone()).collect(), } } } @@ -127,13 +121,7 @@ where { fn from(me: SerializedState) -> Self { Self { - vaults: me.vaults.into_iter().fold( - HashMap::new(), - |mut acc: HashMap<String, Option<V>>, k| { - acc.insert(k, None); - acc - }, - ), + vaults: me.vaults.into_iter().map(|k| (k, None)).collect(), _phantom: PhantomData, ..Default::default() } |