1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use petgraph::graph::NodeIndex;
use std::any::Any;
use std::ops;
pub mod add;
pub trait State: Any + 'static {
fn n_outlets(&self) -> u32;
fn n_inlets(&self) -> u32;
fn proc_inlet_at_index(&mut self, Inlet, incoming: &Any);
fn proc_outlet_at_index(&mut self, Outlet) -> &Any;
fn outlet_ref(&self, Outlet) -> &Any;
}
pub type ConnectionIndex = u32;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Inlet(pub ConnectionIndex);
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Outlet(pub ConnectionIndex);
pub type Index = NodeIndex<super::Index>;
pub struct Node {
pub state: Box<State>,
}
pub struct Container<I, N, O> {
pub inlets: I,
pub node: N,
pub outlet: Option<O>,
}
impl State for Box<State> {
fn n_outlets(&self) -> u32 {
(**self).n_outlets()
}
fn n_inlets(&self) -> u32 {
(**self).n_inlets()
}
fn proc_inlet_at_index(&mut self, i: Inlet, incoming: &Any) {
(**self).proc_inlet_at_index(i, incoming)
}
fn proc_outlet_at_index(&mut self, i: Outlet) -> &Any {
(**self).proc_outlet_at_index(i)
}
fn outlet_ref(&self, i: Outlet) -> &Any {
(**self).outlet_ref(i)
}
}
impl ops::Deref for Node {
type Target = State;
fn deref(&self) -> &Self::Target {
&self.state
}
}
impl ops::DerefMut for Node {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.state
}
}