diff --git a/crates/compute_graph/src/lib.rs b/crates/compute_graph/src/lib.rs index 6900b67..5d9db22 100644 --- a/crates/compute_graph/src/lib.rs +++ b/crates/compute_graph/src/lib.rs @@ -8,8 +8,8 @@ use builder::{BuildGraphError, GraphBuilder}; use node::{ErasedNode, NodeValue}; use petgraph::visit::{IntoEdgeReferences, NodeIndexable}; use petgraph::{stable_graph::StableDiGraph, visit::EdgeRef}; -use rule::{AsyncRule, InputVisitor, Rule}; -use std::cell::{Cell, Ref, RefCell}; +use rule::{AsyncRule, Input, InputVisitor, Rule}; +use std::cell::{Cell, RefCell}; use std::collections::HashMap; use std::collections::VecDeque; use std::ops::{Deref, DerefMut}; @@ -198,31 +198,6 @@ impl Graph { } } -#[derive(Debug)] -pub struct Input { - node_idx: NodeId, - value: Rc>>, -} - -impl Input { - pub fn value(&self) -> impl Deref + '_ { - Ref::map(self.value.borrow(), |opt| { - opt.as_ref() - .expect("node must be evaluated before reading value") - }) - } -} - -// can't derive this impl because it incorectly adds the bound T: Clone -impl Clone for Input { - fn clone(&self) -> Self { - Self { - node_idx: self.node_idx, - value: Rc::clone(&self.value), - } - } -} - // TODO: there's a lot happening here, make sure this doesn't create a reference cycle pub struct InvalidationSignal { node_idx: Rc>>, diff --git a/crates/compute_graph/src/rule.rs b/crates/compute_graph/src/rule.rs index b505861..dbc32dd 100644 --- a/crates/compute_graph/src/rule.rs +++ b/crates/compute_graph/src/rule.rs @@ -1,5 +1,8 @@ use crate::node::NodeValue; -use crate::Input; +use crate::NodeId; +use std::cell::{Ref, RefCell}; +use std::ops::Deref; +use std::rc::Rc; pub trait Rule: 'static { type Output: NodeValue; @@ -17,6 +20,33 @@ pub trait AsyncRule: 'static { async fn evaluate(&mut self) -> Self::Output; } +#[derive(Debug)] +pub struct Input { + pub(crate) node_idx: NodeId, + pub(crate) value: Rc>>, +} + +impl Input { + pub fn value(&self) -> impl Deref + '_ { + Ref::map(self.value.borrow(), |opt| { + opt.as_ref() + .expect("node must be evaluated before reading value") + }) + } +} + +// can't derive this impl because it incorectly adds the bound T: Clone +impl Clone for Input { + fn clone(&self) -> Self { + Self { + node_idx: self.node_idx, + value: Rc::clone(&self.value), + } + } +} + +// TODO: i really want Input to be able to implement Deref somehow + pub trait InputVisitor { fn visit(&mut self, input: &Input); }