From 67fb9db4617dc86d1c5bf4cd542542f70a4b1c2e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 29 Oct 2024 16:20:45 -0400 Subject: [PATCH] Cleanup --- crates/graph/src/lib.rs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/crates/graph/src/lib.rs b/crates/graph/src/lib.rs index d33f238..d182d05 100644 --- a/crates/graph/src/lib.rs +++ b/crates/graph/src/lib.rs @@ -89,6 +89,7 @@ impl Graph { let sorted = petgraph::algo::toposort(&*self.node_graph.borrow(), None); if let Err(_cycle) = sorted { + self.node_graph.borrow_mut().clear_edges(); // TODO: actually build a vec describing the cycle path for debugging return Err(GraphFreezeError::Cyclic(vec![])); } @@ -138,8 +139,6 @@ impl FrozenGraph { } let node = &mut self.node_graph.borrow_mut()[idx]; - // Update the inputs of in this node's struct. - // Actually update the node's value. (node.update)(&mut node.any); } @@ -149,7 +148,7 @@ impl FrozenGraph { self.update_node(self.output); let graph = self.node_graph.borrow(); let node = &graph[self.output].expect_type::(); - node.value() + node.value_rc().borrow().clone().unwrap() } pub fn node_count(&self) -> usize { @@ -193,7 +192,7 @@ impl Input { .as_ref() .borrow() .clone() - .expect("Input must be updated before being deref'd") + .expect("Input cannot be accessed before referent node is updated") } } @@ -274,8 +273,6 @@ trait Node { fn update(&mut self); // TODO: are these both necessary? fn value_rc(&self) -> Rc>>; - // TODO: it would be nice if this borrowed and didn't require Clone - fn value(&self) -> Value; } struct ConstNode(V); @@ -294,10 +291,6 @@ impl Node for ConstNode { fn value_rc(&self) -> Rc>> { Rc::new(RefCell::new(Some(self.0.clone()))) } - - fn value(&self) -> V { - self.0.clone() - } } struct RuleNode { @@ -344,14 +337,6 @@ impl + 'static, V: Clone + 'static> Node for RuleNode { fn value_rc(&self) -> Rc>> { Rc::clone(&self.value) } - - fn value(&self) -> V { - self.value - .as_ref() - .borrow() - .clone() - .expect("RuleNode must be updated before getting value") - } } pub trait Rule { @@ -372,7 +357,7 @@ mod tests { fn erase_node() { let node = ErasedNode::new(ConstNode(1234 as i32)); let unwrapped = node.expect_type::(); - assert_eq!(unwrapped.value(), 1234); + assert_eq!(unwrapped.value_rc().borrow().unwrap(), 1234); } struct ConstantRule(i32);