#[non_exhaustive]
pub enum Message<'a> { SendData(Offset, Data<'a>), DataChunksSent(ChunkCount), Hello(Address), QueryState(Address), ReportState(Address, State), RequestOperation(Address, Operation), AckOperation(Address, Operation), PixelsComplete(Address), Goodbye(Address), Unknown(Frame<'a>), }
Expand description

High-level representation of a sign bus communication message.

Ascribes meaning to a Frame and is freely convertible to and from one (with Unknown to allow round-tripping unknown message types). This is the primary way that messages are represented in flipdot.

§Examples

use flipdot_core::{Address, Message, PageFlipStyle, SignBus, State};
use flipdot_testing::{VirtualSign, VirtualSignBus};

let mut bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3), PageFlipStyle::Manual)]);

// Message is the currency used to send and receive messages on a bus:
let response = bus.process_message(Message::QueryState(Address(3)))?;
assert_eq!(Some(Message::ReportState(Address(3), State::Unconfigured)), response);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

SendData(Offset, Data<'a>)

Send a chunk of data, with the first member indicating the offset.

E.g. when sending 32 bytes of data in two 16-byte chunks, the first message would have offset 0 and the second would have offset 16. No response is expected.

§

DataChunksSent(ChunkCount)

Notifies that we are done sending data, and specifies how many chunks were sent.

No response is expected.

§

Hello(Address)

Initially discovers the sign with the given address on the bus.

A ReportState message with the sign’s current state is expected.

§

QueryState(Address)

Queries the sign with the given address for its current state.

A ReportState message with the sign’s current state is expected.

§

ReportState(Address, State)

Indicates the state of the sign with the given address.

Sent by the sign in response to a Hello orQueryState message.

§

RequestOperation(Address, Operation)

Requests that the sign with the given address perform an operation.

An AckOperation response is expected.

§

AckOperation(Address, Operation)

Sent by the sign with the given address indicating that it will perform the given operation.

§

PixelsComplete(Address)

Indicates that the pixel data for the sign with the given address has been fully transferred.

This indicates that the sign should load it into memory in preparation to show. No response is expected.

§

Goodbye(Address)

Notifies the sign with the given address to blank its display and shut down.

The sign will not be usable for 30 seconds after receiving this message. Generally optional as disconnecting switched power from the sign should have the same effect. No response is expected.

§

Unknown(Frame<'a>)

Wraps a Frame that does not correspond to any known message.

Trait Implementations§

source§

impl<'a> Clone for Message<'a>

source§

fn clone(&self) -> Message<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Message<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Message<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Provides a human-readable view of the message.

This is useful, for example, when monitoring the traffic on a bus.

source§

impl<'a> From<Frame<'a>> for Message<'a>

source§

fn from(frame: Frame<'a>) -> Self

Converts a Frame into a Message.

This cannot fail as all valid Frames are representable as Messages (though perhaps Unknown). The input Frame is consumed to allow efficiently reusing its data where possible.

§Examples
let frame = Frame::new(Address(0x12), MsgType(4), Data::try_new(vec![0x07])?);
let message = Message::from(frame);
assert_eq!(Message::ReportState(Address(0x12), State::ConfigReceived), message);
source§

impl<'a> From<Message<'a>> for Frame<'a>

source§

fn from(message: Message<'a>) -> Self

Converts a Message into a Frame.

This cannot fail as all Messages can be represented as Frames. The input Message is consumed to allow efficiently reusing its data where possible.

§Examples
let message = Message::ReportState(Address(0xFF), State::ConfigReceived);
let frame = Frame::from(message);
assert_eq!(Frame::new(Address(0xFF), MsgType(4), Data::try_new(vec![0x07])?), frame);
source§

impl<'a> Hash for Message<'a>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> PartialEq for Message<'a>

source§

fn eq(&self, other: &Message<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for Message<'a>

source§

impl<'a> StructuralPartialEq for Message<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Message<'a>

§

impl<'a> Send for Message<'a>

§

impl<'a> Sync for Message<'a>

§

impl<'a> Unpin for Message<'a>

§

impl<'a> UnwindSafe for Message<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.