diff options
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/mod.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/models/mod.rs b/src/models/mod.rs index a252f51..ddef71f 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -1,4 +1,21 @@ -use serde::{Deserialize, Serialize}; +use crate::error::TwinHError; +use bincode::deserialize; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use sled::IVec; + +pub struct Entity<M: DeserializeOwned + Serialize> { + pub umrn: u64, + pub model: M, +} + +impl<M: DeserializeOwned + Serialize> Entity<M> { + pub fn new(t: (IVec, IVec)) -> Result<Self, TwinHError> { + let (umrn, model) = t; + let umrn = deserialize(&umrn)?; + let model = deserialize(&model)?; + Ok(Entity { umrn, model }) + } +} #[derive(Serialize, Deserialize)] pub struct Part { @@ -12,7 +29,6 @@ pub struct Part { #[derive(Serialize, Deserialize)] pub struct Car { - pub key: u64, pub doors: u8, //pub engine: Engine, pub make: String, |