Struct flipdot_testing::VirtualSignBus[][src]

pub struct VirtualSignBus<'a> { /* fields omitted */ }

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_serial::SerialSignBus;
use flipdot_testing::{Address, Odk, VirtualSign, VirtualSignBus};

let bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3))]);
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

impl<'a> VirtualSignBus<'a>[src]

pub fn new<I>(signs: I) -> Self where
    I: IntoIterator<Item = VirtualSign<'a>>, 
[src]

Creates a new VirtualSignBus with the specified virtual signs.

Examples

let bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3))]);
let port = serial::open("COM3")?;
let odk = Odk::try_new(port, bus)?;

pub fn sign(&self, index: usize) -> &VirtualSign<'a>[src]

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)), VirtualSign::new(Address(16))];
let bus = VirtualSignBus::new(signs);
let second_sign = bus.sign(1);
assert_eq!(Address(16), second_sign.address());

Trait Implementations

impl<'a> Clone for VirtualSignBus<'a>[src]

impl<'a> Debug for VirtualSignBus<'a>[src]

impl<'a> Eq for VirtualSignBus<'a>[src]

impl<'a> Hash for VirtualSignBus<'a>[src]

impl<'a> PartialEq<VirtualSignBus<'a>> for VirtualSignBus<'a>[src]

impl SignBus for VirtualSignBus<'_>[src]

fn process_message<'a>(
    &mut self,
    message: Message<'_>
) -> Result<Option<Message<'a>>, Box<dyn Error + Send + Sync>>
[src]

Handles a bus message by trying each sign in turn to see if it can handle it (i.e. returns a Some response).

impl<'a> StructuralEq for VirtualSignBus<'a>[src]

impl<'a> StructuralPartialEq for VirtualSignBus<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for VirtualSignBus<'a>

impl<'a> Send for VirtualSignBus<'a>

impl<'a> Sync for VirtualSignBus<'a>

impl<'a> Unpin for VirtualSignBus<'a>

impl<'a> UnwindSafe for VirtualSignBus<'a>

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.