parent
f60e444c68
commit
f17bd20516
3 changed files with 36 additions and 4 deletions
|
@ -1,2 +1,4 @@
|
|||
/// Node abstraction
|
||||
pub mod node;
|
||||
/// State
|
||||
pub mod state;
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,3 @@ pub struct Property {
|
|||
pub name: String,
|
||||
pub data: DataType
|
||||
}
|
||||
|
||||
impl Property {
|
||||
}
|
Loading…
Reference in a new issue