Expand description
The Step
trait
The Step trait defines a powerful but simple API that allows the CoAP runtime to be a composition of “steps,” stored as a type-level linked list.
e.g.
Gather Ingredients
-> Mix Wet Ingredients
-> Mix Dry Ingredients
-> Mix Everything together
-> Pour into cake tin
-> Bake
as Steps:
Bake<PourIntoCakeTin<MixEverything<MixDry<MixWet<GatherIngredients<Empty>>>>>>
Capabilities
- May read system state (time, dgram on the socket, platform configuration)
- May maintain internal state
- Must be managed with interior mutability (e.g.
RwLock
)
- Must be managed with interior mutability (e.g.
- May perform side effects
platform::Effect
provides deterministic API for logging and sending bytes over the wire
- May participate in client role, server role, or both roles in the CoAP runtime
step::Step::poll_req
(server)step::Step::poll_resp
(client)
- May modify messages before they are sent
- May be notified whenever a message is sent
- May yield data to the outer step
Determinism
Steps provided by this crate will never perform any observable IO,
aside from managing their own internal state and appending to the list of
effects provided in the poll_req
/poll_resp
fns.
Logging
Steps provided by this crate will never log to any streams directly,
and will provide them via platform::Effect::Log
.
It is strongly recommended that log::Level::Warn
and
log::Level::Error
messages are not ignored.
Re-exports
Modules
- ACK incoming messages
- Ensure clients only receive relevant response
- Ignore ACKs we don’t recognize
- Observe
- Parse messages from dgrams
- Assign message Ids to those with Id(0)
- Assign message tokens to those with Token(0)
- Buffer & resend messages until they get a sufficient response
- Standard set of Steps
- Set standard options on outbound messages
Macros
- Specialized
?
operator for use in step bodies, allowing early-exit forResult
,Option<Result>
andOption<nb::Result>
. - Macro to execute inner steps, converting the
Option<nb::Result<T, E>>
toOption<T>
by returning the inner step’s Errors & WouldBlock - Issue an
Effect::Log
Traits
- An error that can be returned by a
Step
. - A step in the message-handling CoAP runtime.