Trait coap_message::ReadableMessage

source ·
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§

source

type Code: Code

source

type MessageOption<'a>: MessageOption where Self: 'a

Type of an individual option, indiciating its option number and value

source

type OptionsIter<'a>: Iterator<Item = Self::MessageOption<'a>> where Self: 'a

Required Methods§

source

fn code(&self) -> Self::Code

Get the code (request method or response code) of the message

See Code for its details.

source

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.

source

fn payload(&self) -> &[u8]

Get the payload set in the message

This is necessarily empty for messages of some codes.

Provided Methods§

source

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.

Object Safety§

This trait is not object safe.

Implementors§