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§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more