Struct flipdot_testing::VirtualSign
source · pub struct VirtualSign<'a> { /* private fields */ }
Expand description
Mock implementation of a single sign on a VirtualSignBus
.
Encapsulates all the state associated with a virtual sign and implements the sign protocol for it.
In general, you do not need to interact with this class directly; you simply pass it off to a
VirtualSignBus
, which forwards messages appropriately.
§Examples
See VirtualSignBus
.
Implementations§
source§impl VirtualSign<'_>
impl VirtualSign<'_>
sourcepub fn new(address: Address, flip_style: PageFlipStyle) -> Self
pub fn new(address: Address, flip_style: PageFlipStyle) -> Self
Creates a new VirtualSign
with the specified address and page flip style.
§Examples
let sign = VirtualSign::new(Address(22), PageFlipStyle::Manual);
let bus = VirtualSignBus::new(iter::once(sign));
sourcepub fn address(&self) -> Address
pub fn address(&self) -> Address
Returns the sign’s address.
§Examples
let sign = VirtualSign::new(Address(22), PageFlipStyle::Manual);
assert_eq!(Address(22), sign.address());
sourcepub fn state(&self) -> State
pub fn state(&self) -> State
Returns the sign’s current state.
§Examples
let sign = VirtualSign::new(Address(3), PageFlipStyle::Manual);
assert_eq!(State::Unconfigured, sign.state());
sourcepub fn sign_type(&self) -> Option<SignType>
pub fn sign_type(&self) -> Option<SignType>
Returns the sign’s configured type.
This is initially None
and will only be set if the sign has received a configuration message over the bus.
Note that even if it has, this may still be None
if the configuration did not match any known types
(e.g. potentially when driving from a real ODK).
§Examples
let sign = VirtualSign::new(Address(17), PageFlipStyle::Manual);
assert_eq!(None, sign.sign_type());
sourcepub fn process_message<'a>(
&mut self,
message: &Message<'_>
) -> Option<Message<'a>>
pub fn process_message<'a>( &mut self, message: &Message<'_> ) -> Option<Message<'a>>
Handle a bus message, updating our state accordingly.
§Examples
let mut sign = VirtualSign::new(Address(3), PageFlipStyle::Manual);
let response = sign.process_message(&Message::QueryState(Address(3)));
assert_eq!(Some(Message::ReportState(Address(3), State::Unconfigured)), response);
Trait Implementations§
source§impl<'a> Clone for VirtualSign<'a>
impl<'a> Clone for VirtualSign<'a>
source§fn clone(&self) -> VirtualSign<'a>
fn clone(&self) -> VirtualSign<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for VirtualSign<'a>
impl<'a> Debug for VirtualSign<'a>
source§impl<'a> Hash for VirtualSign<'a>
impl<'a> Hash for VirtualSign<'a>
source§impl<'a> PartialEq for VirtualSign<'a>
impl<'a> PartialEq for VirtualSign<'a>
source§fn eq(&self, other: &VirtualSign<'a>) -> bool
fn eq(&self, other: &VirtualSign<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.