Struct tis_100::io::IoBus
[−]
[src]
pub struct IoBus { /* fields omitted */ }
An IoBus
is used to pass messages between nodes. Nodes are represented by usize
indices.
Nodes must first be connected before they can pass messages. Nodes can be connected using either
half-duplex or full-duplex channels.
Once nodes are connected, they can pass messages through the IoBus using an IoBusView
.
An IoBusView
ensures that a node can only read or write the ports that it is connected to.
All writes are buffered. In order for a node to read a value that another node has sent it,
the writes must be committed.
Examples
use tis_100::core::Port::*; use tis_100::io::IoBus; let mut bus = IoBus::new(); // In this example, 1 is right from 0, and 0 is left from 1. bus.connect_full(0, 1, RIGHT); assert!(bus.is_connected(0, 1, RIGHT)); assert!(bus.is_connected(1, 0, LEFT));
use tis_100::core::Port::*; use tis_100::io::IoBus; let mut bus = IoBus::new(); bus.connect_half(0, 1, RIGHT); { let mut view = bus.view(0); view.write(RIGHT, 42); } bus.commit(); { let mut view = bus.view(1); assert_eq!(view.read(LEFT), Some(42)); }
Methods
impl IoBus
[src]
fn new() -> IoBus
Construct a new, empty IoBus
.
fn connect_half(&mut self, from: NodeId, to: NodeId, port: Port) -> &mut Self
Create a one-way connection from one node to another in the given direction.
fn connect_full(&mut self, from: NodeId, to: NodeId, port: Port) -> &mut Self
Create a two-way connection from one node to another in the given direction. The opposite direction will be used when connecting the second half.
fn is_connected(&self, from: NodeId, to: NodeId, port: Port) -> bool
Determine if two nodes are connected in a certain direction.
fn view<'a>(&'a mut self, node: NodeId) -> IoBusView<'a>
Returns a view of the IoBus
for the given node.
fn commit(&mut self)
Commits all outstanding writes and clears the write buffer.