Cleanup
This commit is contained in:
parent
140c6a67fd
commit
67fb9db461
@ -89,6 +89,7 @@ impl<Output: Clone + 'static> Graph<Output> {
|
|||||||
|
|
||||||
let sorted = petgraph::algo::toposort(&*self.node_graph.borrow(), None);
|
let sorted = petgraph::algo::toposort(&*self.node_graph.borrow(), None);
|
||||||
if let Err(_cycle) = sorted {
|
if let Err(_cycle) = sorted {
|
||||||
|
self.node_graph.borrow_mut().clear_edges();
|
||||||
// TODO: actually build a vec describing the cycle path for debugging
|
// TODO: actually build a vec describing the cycle path for debugging
|
||||||
return Err(GraphFreezeError::Cyclic(vec![]));
|
return Err(GraphFreezeError::Cyclic(vec![]));
|
||||||
}
|
}
|
||||||
@ -138,8 +139,6 @@ impl<Output: Clone + 'static> FrozenGraph<Output> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let node = &mut self.node_graph.borrow_mut()[idx];
|
let node = &mut self.node_graph.borrow_mut()[idx];
|
||||||
// Update the inputs of in this node's struct.
|
|
||||||
|
|
||||||
// Actually update the node's value.
|
// Actually update the node's value.
|
||||||
(node.update)(&mut node.any);
|
(node.update)(&mut node.any);
|
||||||
}
|
}
|
||||||
@ -149,7 +148,7 @@ impl<Output: Clone + 'static> FrozenGraph<Output> {
|
|||||||
self.update_node(self.output);
|
self.update_node(self.output);
|
||||||
let graph = self.node_graph.borrow();
|
let graph = self.node_graph.borrow();
|
||||||
let node = &graph[self.output].expect_type::<Output>();
|
let node = &graph[self.output].expect_type::<Output>();
|
||||||
node.value()
|
node.value_rc().borrow().clone().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_count(&self) -> usize {
|
pub fn node_count(&self) -> usize {
|
||||||
@ -193,7 +192,7 @@ impl<T: Clone + 'static> Input<T> {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.borrow()
|
.borrow()
|
||||||
.clone()
|
.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<Value> {
|
|||||||
fn update(&mut self);
|
fn update(&mut self);
|
||||||
// TODO: are these both necessary?
|
// TODO: are these both necessary?
|
||||||
fn value_rc(&self) -> Rc<RefCell<Option<Value>>>;
|
fn value_rc(&self) -> Rc<RefCell<Option<Value>>>;
|
||||||
// TODO: it would be nice if this borrowed and didn't require Clone
|
|
||||||
fn value(&self) -> Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ConstNode<V>(V);
|
struct ConstNode<V>(V);
|
||||||
@ -294,10 +291,6 @@ impl<V: Clone + 'static> Node<V> for ConstNode<V> {
|
|||||||
fn value_rc(&self) -> Rc<RefCell<Option<V>>> {
|
fn value_rc(&self) -> Rc<RefCell<Option<V>>> {
|
||||||
Rc::new(RefCell::new(Some(self.0.clone())))
|
Rc::new(RefCell::new(Some(self.0.clone())))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value(&self) -> V {
|
|
||||||
self.0.clone()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RuleNode<R, V> {
|
struct RuleNode<R, V> {
|
||||||
@ -344,14 +337,6 @@ impl<R: Rule<V> + 'static, V: Clone + 'static> Node<V> for RuleNode<R, V> {
|
|||||||
fn value_rc(&self) -> Rc<RefCell<Option<V>>> {
|
fn value_rc(&self) -> Rc<RefCell<Option<V>>> {
|
||||||
Rc::clone(&self.value)
|
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<Output> {
|
pub trait Rule<Output> {
|
||||||
@ -372,7 +357,7 @@ mod tests {
|
|||||||
fn erase_node() {
|
fn erase_node() {
|
||||||
let node = ErasedNode::new(ConstNode(1234 as i32));
|
let node = ErasedNode::new(ConstNode(1234 as i32));
|
||||||
let unwrapped = node.expect_type::<i32>();
|
let unwrapped = node.expect_type::<i32>();
|
||||||
assert_eq!(unwrapped.value(), 1234);
|
assert_eq!(unwrapped.value_rc().borrow().unwrap(), 1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ConstantRule(i32);
|
struct ConstantRule(i32);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user