Struct flipdot_testing::VirtualSignBus [−][src]
Mock implementation of a bus containing one or more signs.
The bus is populated with one or more VirtualSign
s 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]
I: IntoIterator<Item = VirtualSign<'a>>,
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]
fn clone(&self) -> VirtualSignBus<'a>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Debug for VirtualSignBus<'a>
[src]
impl<'a> Eq for VirtualSignBus<'a>
[src]
impl<'a> Hash for VirtualSignBus<'a>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> PartialEq<VirtualSignBus<'a>> for VirtualSignBus<'a>
[src]
fn eq(&self, other: &VirtualSignBus<'a>) -> bool
[src]
fn ne(&self, other: &VirtualSignBus<'a>) -> bool
[src]
impl SignBus for VirtualSignBus<'_>
[src]
fn process_message<'a>(
&mut self,
message: Message<'_>
) -> Result<Option<Message<'a>>, Box<dyn Error + Send + Sync>>
[src]
&mut self,
message: Message<'_>
) -> Result<Option<Message<'a>>, Box<dyn Error + Send + Sync>>
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,