TypeRenderable

Trait TypeRenderable 

Source
pub trait TypeRenderable:
    GetRenderable
    + PostRenderable
    + PutRenderable
    + DeleteRenderable
    + FetchRenderable
    + IPatchRenderable { }
Expand description

A Handler trait that supports various CoAP methods on a data structure that can be serialized, eg. in CBOR.

A TypeRenderable implementation can be turned into a Handler by wrapping it in TypeHandler::new_*.

This is a composite trait of many per-method traits because all those traits come with their own associated types (and maybe constants), and as long as neither of those can be provided like methods can be (i.e., added later extensibly, allowing for defaults), those are more easily handled by composition.

Unless you can keep track of changes to the list of trait dependencies, use the with_get_put_fetch()-style wrappers around instances, which mark all other methods as unimplemented.

For different methods, the functions get called at different times in the request/response handling sequence: A GET’s method is called when the response is prepared, whereas a PUT’s method is called when the request is prepared. This ensures that for CoAP server implementations that delay rendering (e.g. as part of retransmission handling), no large data needs to be kept for long. The methods with both input and output data (POST, FETCH) are called according to their most expected usage pattern: FetchRenderable::fetch() is called at response time (because the request payload is typically a small filter expression that limits the output to something that fits within a CoAP response but may still be large), whereas IPatchRenderable::ipatch() is called immediately (because it is frequently used with empty outputs).

Implementors§