diff options
author | Katharina Sabel <katharina.sabel@asquera.de> | 2018-05-07 16:10:54 +0200 |
---|---|---|
committer | Katharina Sabel <katharina.sabel@asquera.de> | 2018-05-07 16:10:54 +0200 |
commit | b506e5968cc257f256a36064a309b4c2f19e37ab (patch) | |
tree | efe78196b73fd8eb1983b8fc57a3cb8e4913ea06 /lockchain-core/src/record.rs | |
parent | cb7612ae9e1bcea664f3e320c7e5ba0cc95cffa0 (diff) |
Fleshing out basic traits provided by lockchain-core
Diffstat (limited to '')
-rw-r--r-- | lockchain-core/src/record.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lockchain-core/src/record.rs b/lockchain-core/src/record.rs index 9a5d9ef..717aefb 100644 --- a/lockchain-core/src/record.rs +++ b/lockchain-core/src/record.rs @@ -11,7 +11,9 @@ use chrono::{DateTime, Local}; use std::collections::BTreeMap; -use traits::Body; +use serde::{de::DeserializeOwned, Serialize}; + +// use traits::Body; /// An enum that wraps around all possible data types to store /// as the value of a vault record. @@ -62,5 +64,19 @@ pub struct Header { #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)] pub struct Record<T: Body> { pub header: Header, - pub body: Option<Box<T::Impl>>, + #[serde(bound(deserialize = "T: Body"))] + pub body: Option<T>, +} + +/// A Body trait that can be implemented to hook into the generic Record +/// data module. +/// +/// This allows working with both encrypted and cleartext data bodies. +pub trait Body: DeserializeOwned + Serialize { + ///Get the value of a field from this body + fn get_field(&self, key: &str) -> Option<Payload>; + /// Set the value of a field + fn set_field(&mut self, key: &str, value: &Payload); + /// Remove versioning and flatten the data tree to a single level. + fn flatten(&mut self); } |