1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
use super::{FlowArena, FlowNode, Node}; use std::fmt::{self, Debug}; pub type NodePure<Id> = FlowNode<Id, ()>; pub type FlowPure<Id> = FlowArena<Id, FlowNode<Id, ()>>; pub struct GraphNode<Id, Entity> { id: Id, entity: Entity, children: Vec<Id>, } impl<Id, Entity> Debug for GraphNode<Id, Entity> where Id: Debug + Clone, Entity: Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct(format!("{:?}", self.id()).as_str()) .field(">>", &self.children) .field("::", &self.entity) .finish() } } impl<Id, Entity> Node<Id> for GraphNode<Id, Entity> where Id: Debug + Clone, Entity: Debug, { fn id(&self) -> &Id { &self.id } fn parent(&self) -> Option<Id> { None } fn parent_set(&mut self, _: Id) {} fn parent_set_none(&mut self) {} fn children(&self) -> Vec<Id> { self.children.clone() } fn children_ref_mut(&mut self) -> &mut Vec<Id> { &mut self.children } } pub type GraphArena<Id, Entity> = FlowArena<Id, GraphNode<Id, Entity>>;