Trait coap_message::Code

source ·
pub trait Code: Into<u8> + TryFrom<u8> {
    type Error: Debug + RenderableOnMinimal;

    // Required method
    fn new(code: u8) -> Result<Self, <Self as Code>::Error>;
}
Expand description

A message code A CoAP code

For the code’s meaning, see the CoAP Codes IANA subregistry or the coap_numbers::code module that lists them.

All code implementations can be converted to u8 (as they correspond to an 8-bit unsigned integer in the CoAP protocol). The conversion back is fallible to allow strict message implementations to only accept codes supported by the implementation, and/or to limit the values by type state. For example, a strict implementation may distinguish between request and response messages, and only allow the respective code class into their objects (simultaneously creating usable niches in the in-memory representations).

Required Associated Types§

source

type Error: Debug + RenderableOnMinimal

Error of the .new() method; ideally, this is also the TryFrom::Error (which can not be restricted without Associated type bounds being stabilized).

Once that is available, the built-in new method will be deprecated and eventually removed – a change that will be trivial on code using it provided that this error is indeed the error of TryFrom.

The error, when rendered, should represent a 5.00 style error, because what went wrong was that the server CoAP library can not represent the response code intended by the handler.

Required Methods§

source

fn new(code: u8) -> Result<Self, <Self as Code>::Error>

This constructor is a more concrete variant of the TryFrom function whose error code is practically usable (see Self::Error)

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Code for u8

§

type Error = Infallible

source§

fn new(code: u8) -> Result<Self, Infallible>

Implementors§