[][src]Struct graphity::signal::SignalGraph

pub struct SignalGraph<N, NI, CI, PI> where
    N: NodeWrapper<Class = NI::Class, Consumer = NI::Consumer, Producer = NI::Producer>,
    NI: NodeIndex<ConsumerIndex = CI, ProducerIndex = PI>,
    CI: ConsumerIndex<NodeIndex = NI, Consumer = NI::Consumer>,
    PI: ProducerIndex<NodeIndex = NI, Producer = NI::Producer>, 
{ /* fields omitted */ }

A graph structure meant to model signal flow between registered nodes.

Signal graph can be populated with nodes, then producers and consumers of these nodes can be wired up together. It is intended to be used for signal modeling, where nodes are wired up through their producer and consumer pins, processing data, passing it through.

Each producer can be connected to any number of consumers. Every consumer must be fed by one producer at most.

When edges in the graph form a cycle, a feedback is introduced. That means that data passing through the cycle will be delayed by a single tick and only then fed to the consumer.

This structure is not meant to be used directly, instead, user should use the graphity macro to generate it from given nodes.

Implementations

impl<N, NI, CI, PI> SignalGraph<N, NI, CI, PI> where
    N: NodeWrapper<Class = NI::Class, Consumer = NI::Consumer, Producer = NI::Producer>,
    NI: NodeIndex<ConsumerIndex = CI, ProducerIndex = PI>,
    CI: ConsumerIndex<NodeIndex = NI, Consumer = NI::Consumer>,
    PI: ProducerIndex<NodeIndex = NI, Producer = NI::Producer>, 
[src]

pub fn new() -> Self[src]

Initialize a new empty graph.

Example

Generate SignalGraph implementation using the graphity macro. Then initialize it. Read the macro documentation to learn how to define the graph.

graphity!(
    ...
);

let mut graph = Graph::new();

pub fn add_node<IntoN>(&mut self, node: IntoN) -> NI where
    IntoN: Into<N>, 
[src]

Add a node of the registered typo into the graph.

The method then returns an index of the node. That can be later used to access the node or any of its consumers/producers.

let generator = graph.add_node(Generator(1));
let echo = graph.add_node(Echo::default());

pub fn remove_node(&mut self, node_index: NI)[src]

Remove a previously added node.

Does nothing if the node_index does not match an existing node. It will remove all inbound and outbound edges of this node.

Example

graph.remove_node(generator);

pub fn node(&self, node_index: &NI) -> Option<&N>[src]

Access a node stored in the graph.

Returns None if the node_index references a non-existent node.

Example

let node = graph.node(generator);

pub fn node_mut(&mut self, node_index: &NI) -> Option<&mut N>[src]

Mutably access a node stored in the graph.

Returns None if the node_index references a non-existent node.

Example

let mut node = graph.node_mut(generator);

pub fn add_edge(
    &mut self,
    producer: PI,
    consumer: CI
) -> Result<(), AddEdgeError>
[src]

Add an edge connecting producer of one node to a consumer of another.

Errors

Will return an error if the consumer is already connected to a different producer.

Example

graph.add_edge(
    generator.producer(GeneratorProducer),
    echo.consumer(EchoConsumer),
).unwrap();

generator and echo are indices previously returned by add_node. GeneratorProducer and EchoConsumer are types defined by the user and bound to their respective nodes.

pub fn must_add_edge(&mut self, producer: PI, consumer: CI)[src]

Add an edge connecting producer of one node to a consumer of another.

See add_edge for more info.

Panics

Will panic if the consumer is already connected to a different producer.

Example

graph.must_add_edge(
    generator.producer(GeneratorProducer),
    echo.consumer(EchoConsumer),
);

See add_edge for more info.

pub fn remove_edge(&mut self, producer: PI, consumer: CI)[src]

Remove the edge connecting the given producer and consumer.

Does nothing if there is no such edge present.

Example

graph.remove_edge(
    generator.producer(GeneratorProducer),
    echo.consumer(EchoConsumer),
);

pub fn has_edge(&mut self, producer: PI, consumer: CI) -> bool[src]

Check whether the graph contains an edge connecting given producer and consumer.

Example

graph.has_edge(
    generator.producer(GeneratorProducer),
    echo.consumer(EchoConsumer),
);

pub fn tick(&mut self)[src]

Traverse the whole graph and tick all present nodes, passing data through registered edges.

A single tick here performs a single iteration through the whole graph. It triggers tick of each node, gathers generated data from registered producers, passes the data to connected consumers and continues with the transition.

Example

graph.tick();
// Echo: 1
graph.tick();
// Echo: 1

Auto Trait Implementations

impl<N, NI, CI, PI> !Send for SignalGraph<N, NI, CI, PI>[src]

impl<N, NI, CI, PI> !Sync for SignalGraph<N, NI, CI, PI>[src]

impl<N, NI, CI, PI> Unpin for SignalGraph<N, NI, CI, PI> where
    CI: Unpin,
    N: Unpin,
    NI: Unpin,
    PI: Unpin
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.