aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core/src/record.rs
diff options
context:
space:
mode:
authorKatharina Sabel <katharina.sabel@asquera.de>2018-05-07 16:10:54 +0200
committerKatharina Sabel <katharina.sabel@asquera.de>2018-05-07 16:10:54 +0200
commitb506e5968cc257f256a36064a309b4c2f19e37ab (patch)
treeefe78196b73fd8eb1983b8fc57a3cb8e4913ea06 /lockchain-core/src/record.rs
parentcb7612ae9e1bcea664f3e320c7e5ba0cc95cffa0 (diff)
Fleshing out basic traits provided by lockchain-core
Diffstat (limited to 'lockchain-core/src/record.rs')
-rw-r--r--lockchain-core/src/record.rs20
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);
}