Move rules to rule.rs
This commit is contained in:
parent
c18c1ced59
commit
05348a5dbc
@ -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;
|
||||
|
@ -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<S: Synchronicity> InvalidationSignal<S> {
|
||||
|
||||
// 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<T>(&mut self, input: &Input<T>);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
struct ConstantRule<T>(T);
|
||||
impl<T: Clone + NodeValue> Rule for ConstantRule<T> {
|
||||
impl<T: Clone + crate::node::NodeValue> Rule for ConstantRule<T> {
|
||||
type Output = T;
|
||||
fn visit_inputs(&self, _visitor: &mut impl InputVisitor) {}
|
||||
fn evaluate(&mut self) -> Self::Output {
|
||||
|
22
crates/graph/src/rule.rs
Normal file
22
crates/graph/src/rule.rs
Normal file
@ -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<T>(&mut self, input: &Input<T>);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user