Move input to rule.rs
This commit is contained in:
parent
b73d205456
commit
c1c594d4f7
@ -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<O: 'static> Graph<O, Asynchronous> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Input<T> {
|
||||
node_idx: NodeId,
|
||||
value: Rc<RefCell<Option<T>>>,
|
||||
}
|
||||
|
||||
impl<T> Input<T> {
|
||||
pub fn value(&self) -> impl Deref<Target = T> + '_ {
|
||||
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<T> Clone for Input<T> {
|
||||
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<Synch: Synchronicity> {
|
||||
node_idx: Rc<Cell<Option<NodeId>>>,
|
||||
|
@ -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<T> {
|
||||
pub(crate) node_idx: NodeId,
|
||||
pub(crate) value: Rc<RefCell<Option<T>>>,
|
||||
}
|
||||
|
||||
impl<T> Input<T> {
|
||||
pub fn value(&self) -> impl Deref<Target = T> + '_ {
|
||||
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<T> Clone for Input<T> {
|
||||
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<T>(&mut self, input: &Input<T>);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user