diff --git a/domo_lib/src/lib.rs b/domo_lib/src/lib.rs index ed4f9be..57dc335 100644 --- a/domo_lib/src/lib.rs +++ b/domo_lib/src/lib.rs @@ -1,2 +1,4 @@ /// Node abstraction -pub mod node; \ No newline at end of file +pub mod node; +/// State +pub mod state; \ No newline at end of file diff --git a/domo_lib/src/node/mod.rs b/domo_lib/src/node/mod.rs index cba5ce8..57348c6 100644 --- a/domo_lib/src/node/mod.rs +++ b/domo_lib/src/node/mod.rs @@ -1,3 +1,5 @@ +use crate::state::{GetState, State, state_properties::StateProperties, ApplyState}; + use self::property::Property; use domo_proto::identifier::Identifier; use std::collections::HashMap; @@ -99,3 +101,34 @@ impl Node { None } } + +impl GetState for Node { + fn get_state(&self) -> crate::state::State { + let mut s = State::new(); + for p in self.properties.values() { + s.state_properties.push(StateProperties( + self.identifier, + p.clone() + )) + } + for n in self.children.values() { + for p in n.properties.values() { + s.state_properties.push(StateProperties( + n.identifier, + p.clone() + )) + } + } + s + } +} + +impl ApplyState for Node { + fn apply_state(&mut self, state: State) { + for sp in state.state_properties { + if let Some(n) = self.find_mut(&sp.0) { + n.properties.insert(sp.1.name.clone(), sp.1.clone()); + } + } + } +} diff --git a/domo_lib/src/node/property.rs b/domo_lib/src/node/property.rs index 51a48d1..d208441 100644 --- a/domo_lib/src/node/property.rs +++ b/domo_lib/src/node/property.rs @@ -6,7 +6,4 @@ pub struct Property { pub descriptive: bool, pub name: String, pub data: DataType -} - -impl Property { } \ No newline at end of file