[−][src]Trait graphity::node::Node
This trait must be implemented by the user per each node that is to be registered in the signal graph.
Example
The following code presents a Sum
node which offers two consumers
SumConsumer::In1
and SumConsumer::In2
and one producer SumProducer
.
When ticked, this node sums inputs on both consumers and writes the result
to the producer.
#[derive(Default)] pub struct Sum { input1: i32, input2: i32, output: i32, } #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] pub enum SumConsumer { In1, In2, } #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] pub struct SumProducer; impl Node<i32> for Sum { type Consumer = SumConsumer; type Producer = SumProducer; fn tick(&mut self) { self.output = self.input1 + self.input2; } fn read(&self, _producer: Self::Producer) -> i32 { self.output } fn write(&mut self, consumer: Self::Consumer, input: i32) { match consumer { Self::Consumer::In1 => self.input1 = input, Self::Consumer::In2 => self.input2 = input, } } }
Associated Types
type Consumer: Copy + Hash
[src]
User-defined type allowing selection of a specific consumer (input pin) of the given node.
Example
In case multiple consumers are offered by the node:
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] enum ExampleConsumer { Input1, Input2, }
In case only a single consumer is availble:
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] struct ExampleConsumer;
In case there are no consumers avaialble:
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] enum ExampleConsumer {}
type Producer: Copy + Hash
[src]
User-defined type allowing selection of a specific producer (output pin) of the given node.
Example
In case multiple producers are offered by the node:
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] enum ExampleProducer { Input1, Input2, }
In case only a single producer is availble:
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] struct ExampleProducer;
In case there are no producers avaialble:
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] enum ExampleProducer {}
Provided methods
pub fn tick(&mut self)
[src]
Tick signalizes that all the input data were provided and the node can perform its operation on them.
Default implementation does nothing, allowing users to ommit it from their implementation.
pub fn read(&self, producer: Self::Producer) -> T
[src]
Read data from the given producer of the node.
Default implementation returns the default value of carried payload, allowing users to ommit it from their implementation.
pub fn write(&mut self, consumer: Self::Consumer, input: T)
[src]
Write given input data into the given consumer of the node.
Default implementation does nothing, allowing users to ommit it from their implementation.