diff options
author | 53hornet <atc@53hor.net> | 2022-01-01 12:27:41 -0500 |
---|---|---|
committer | 53hornet <atc@53hor.net> | 2022-01-01 12:27:41 -0500 |
commit | d7472320a00fa0bfd6b9be904e0730461f093f61 (patch) | |
tree | eadbbfd9a3b82eaafff30d0114fa7c0c7ca66e7d /src/models | |
parent | 5d2c25bf3b196321ded7b7c7ac9ab9a2021fe9c3 (diff) | |
download | twinh-d7472320a00fa0bfd6b9be904e0730461f093f61.tar.xz twinh-d7472320a00fa0bfd6b9be904e0730461f093f61.zip |
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, |