feat: state
Some checks failed
ci/woodpecker/push/lib Pipeline failed

This commit is contained in:
Strix 2024-01-04 19:36:23 +01:00
parent f60e444c68
commit f17bd20516
No known key found for this signature in database
GPG key ID: 5F35B3B8537287A7
3 changed files with 36 additions and 4 deletions

View file

@ -1,2 +1,4 @@
/// Node abstraction
pub mod node;
/// State
pub mod state;

View file

@ -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());
}
}
}
}

View file

@ -7,6 +7,3 @@ pub struct Property {
pub name: String,
pub data: DataType
}
impl Property {
}