pub trait ReadableMessage {
type Code: Code;
type MessageOption<'a>: MessageOption
where Self: 'a;
type OptionsIter<'a>: Iterator<Item = Self::MessageOption<'a>>
where Self: 'a;
// Required methods
fn code(&self) -> Self::Code;
fn options(&self) -> Self::OptionsIter<'_>;
fn payload(&self) -> &[u8];
// Provided method
fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>> { ... }
}
Expand description
A CoAP message whose code, options and payload can be read
Required Associated Types§
Sourcetype Code: Code
type Code: Code
See Self::code()
Sourcetype MessageOption<'a>: MessageOption
where
Self: 'a
type MessageOption<'a>: MessageOption where Self: 'a
Type of an individual option, indiciating its option number and value
Sourcetype OptionsIter<'a>: Iterator<Item = Self::MessageOption<'a>>
where
Self: 'a
type OptionsIter<'a>: Iterator<Item = Self::MessageOption<'a>> where Self: 'a
See Self::options()
Required Methods§
Sourcefn code(&self) -> Self::Code
fn code(&self) -> Self::Code
Get the code (request method or response code) of the message
See Code for its details.
Sourcefn options(&self) -> Self::OptionsIter<'_>
fn options(&self) -> Self::OptionsIter<'_>
Produce all options in arbitrary order as an iterator
They are sorted if the WithSortedOptions
is implemented as well; implementers should
set that trait whenever they can.
Provided Methods§
Sourcefn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>
fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>
Type ID of Self or a ’static version of Self
This is not useful on its own, and the provided implementation merely returns None.
It can be used by concrete implementations of ReadableMessage that then provide a way to
downcast a &impl ReadableMessage
into a a &Self
. This is only possible for types that
are either 'static
or covariant over their lifetimes. It is up to the implementations to
implement that safely.
Using such downcasts is not generally recommended: It breaks the portability that using coap-message affords. It may still be useful in two kinds of cases:
-
When an implementation specific tool is used deeply within a CoAP handler after using generic middleware. Beware that middleware generally does not make any semver promises on the types it forwards – while it may send on the outermost
impl ReadableMessage
type as-is to its inner handlers, it may just as well wrap them arbitrarily. -
While exploring the evolution of this crate’s traits, these provide an easy hatch.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.