coap_message

Trait 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.

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.

Implementations on Foreign Types§

Source§

impl<T: ReadableMessage> ReadableMessage for &T

Source§

type Code = <T as ReadableMessage>::Code

Source§

type MessageOption<'a> = <T as ReadableMessage>::MessageOption<'a> where Self: 'a

Source§

type OptionsIter<'a> = <T as ReadableMessage>::OptionsIter<'a> where Self: 'a

Source§

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

Source§

fn options(&self) -> Self::OptionsIter<'_>

Source§

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

Implementors§