diff --git a/crates/graph/src/builder.rs b/crates/graph/src/builder.rs index eb3b394..c5acb4f 100644 --- a/crates/graph/src/builder.rs +++ b/crates/graph/src/builder.rs @@ -1,8 +1,9 @@ use crate::node::{AsyncRuleNode, ConstNode, Node, NodeValue, RuleNode}; +use crate::rule::{AsyncRule, Rule}; use crate::util; use crate::{ - AsyncRule, Asynchronous, ErasedNode, Graph, Input, InvalidationSignal, NodeGraph, NodeId, Rule, - Synchronicity, Synchronous, + Asynchronous, ErasedNode, Graph, Input, InvalidationSignal, NodeGraph, NodeId, Synchronicity, + Synchronous, }; use std::cell::{Cell, RefCell}; use std::rc::Rc; diff --git a/crates/graph/src/lib.rs b/crates/graph/src/lib.rs index b198f5f..56249ed 100644 --- a/crates/graph/src/lib.rs +++ b/crates/graph/src/lib.rs @@ -1,12 +1,14 @@ mod builder; mod node; +mod rule; mod synchronicity; mod util; use builder::{BuildGraphError, GraphBuilder}; -use node::{ErasedNode, NodeValue}; +use node::ErasedNode; use petgraph::visit::{IntoEdgeReferences, NodeIndexable}; use petgraph::{stable_graph::StableDiGraph, visit::EdgeRef}; +use rule::{AsyncRule, InputVisitor, Rule}; use std::cell::{Cell, Ref, RefCell}; use std::collections::HashMap; use std::collections::VecDeque; @@ -239,32 +241,12 @@ impl InvalidationSignal { // TODO: i really want Input to be able to implement Deref somehow -pub trait Rule: 'static { - type Output: NodeValue; - - fn visit_inputs(&self, visitor: &mut impl InputVisitor); - - fn evaluate(&mut self) -> Self::Output; -} - -pub trait AsyncRule: 'static { - type Output: NodeValue; - - fn visit_inputs(&self, visitor: &mut impl InputVisitor); - - async fn evaluate(&mut self) -> Self::Output; -} - -pub trait InputVisitor { - fn visit(&mut self, input: &Input); -} - #[cfg(test)] mod tests { use super::*; struct ConstantRule(T); - impl Rule for ConstantRule { + impl Rule for ConstantRule { type Output = T; fn visit_inputs(&self, _visitor: &mut impl InputVisitor) {} fn evaluate(&mut self) -> Self::Output { diff --git a/crates/graph/src/rule.rs b/crates/graph/src/rule.rs new file mode 100644 index 0000000..61d905a --- /dev/null +++ b/crates/graph/src/rule.rs @@ -0,0 +1,22 @@ +use crate::node::NodeValue; +use crate::Input; + +pub trait Rule: 'static { + type Output: NodeValue; + + fn visit_inputs(&self, visitor: &mut impl InputVisitor); + + fn evaluate(&mut self) -> Self::Output; +} + +pub trait AsyncRule: 'static { + type Output: NodeValue; + + fn visit_inputs(&self, visitor: &mut impl InputVisitor); + + async fn evaluate(&mut self) -> Self::Output; +} + +pub trait InputVisitor { + fn visit(&mut self, input: &Input); +}