pub struct VirtualSignBus<'a> { /* private fields */ }Expand description
Mock implementation of a bus containing one or more signs.
The bus is populated with one or more VirtualSigns which actually implement the sign protocol.
VirtualSignBus forwards messages to each virtual sign in turn until one of them handles it.
While most likely not a 100% accurate implementation of the protocol, it is sufficient for interacting with a real ODK.
Messages and responses are logged using the log crate for debugging purposes. Consuming binaries
typically use the env_logger crate and can be run with the RUST_LOG=debug environment variable
to watch the bus messages go by.
§Examples
use flipdot_core::PageFlipStyle;
use flipdot_serial::SerialSignBus;
use flipdot_testing::{Address, Odk, VirtualSign, VirtualSignBus};
let bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3), PageFlipStyle::Manual)]);
let port = serial::open("/dev/ttyUSB0")?;
let mut odk = Odk::try_new(port, bus)?;
loop {
// VirtualSignBus processes the messsages from the real ODK over serial.
odk.process_message()?;
}Implementations§
Source§impl<'a> VirtualSignBus<'a>
impl<'a> VirtualSignBus<'a>
Sourcepub fn new<I>(signs: I) -> Selfwhere
I: IntoIterator<Item = VirtualSign<'a>>,
pub fn new<I>(signs: I) -> Selfwhere
I: IntoIterator<Item = VirtualSign<'a>>,
Creates a new VirtualSignBus with the specified virtual signs.
§Examples
let bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3), PageFlipStyle::Manual)]);
let port = serial::open("COM3")?;
let odk = Odk::try_new(port, bus)?;Sourcepub fn sign(&self, index: usize) -> &VirtualSign<'a>
pub fn sign(&self, index: usize) -> &VirtualSign<'a>
Returns a reference to the VirtualSign at a specific index matching the original order passed to new.
Useful when writing tests in order to verify properties of an individual sign.
§Examples
let signs = vec![VirtualSign::new(Address(5), PageFlipStyle::Manual), VirtualSign::new(Address(16), PageFlipStyle::Manual)];
let bus = VirtualSignBus::new(signs);
let second_sign = bus.sign(1);
assert_eq!(Address(16), second_sign.address());Trait Implementations§
Source§impl<'a> Clone for VirtualSignBus<'a>
impl<'a> Clone for VirtualSignBus<'a>
Source§fn clone(&self) -> VirtualSignBus<'a>
fn clone(&self) -> VirtualSignBus<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more