pub trait AsyncHandler {
// Required methods
fn read(
&self,
ctx: impl ReadContext,
reply: impl ReadReply,
) -> impl Future<Output = Result<(), Error>>;
fn bump_dataver(&self, ctx: impl MatchContext);
// Provided methods
fn read_awaits(&self, _ctx: impl ReadContext) -> bool { ... }
fn write_awaits(&self, _ctx: impl WriteContext) -> bool { ... }
fn invoke_awaits(&self, _ctx: impl InvokeContext) -> bool { ... }
fn write(
&self,
_ctx: impl WriteContext,
) -> impl Future<Output = Result<(), Error>> { ... }
fn invoke(
&self,
_ctx: impl InvokeContext,
_reply: impl InvokeReply,
) -> impl Future<Output = Result<(), Error>> { ... }
fn lifecycle(
&self,
_ctx: impl HandlerContext,
_op: LifecycleOp,
) -> Result<(), Error> { ... }
fn run(
&self,
_ctx: impl HandlerContext,
) -> impl Future<Output = Result<(), Error>> { ... }
}Expand description
A handler for processing a single IM operation: read an attribute, write an attribute, or invoke a command.
Handlers are typically implemented by user-defined clusters, but there is no 1:1 correspondence between a handler and a cluster, as a single handler can handle multiple clusters and even multiple endpoints.
Moreover, the InteractionModel implementation expects a single AsyncHandler instance, so the expectation
is that the user will compose multiple handlers into a single AsyncHandler instance, using ChainedHandler
or other means.
Required Methods§
Sourcefn read(
&self,
ctx: impl ReadContext,
reply: impl ReadReply,
) -> impl Future<Output = Result<(), Error>>
fn read( &self, ctx: impl ReadContext, reply: impl ReadReply, ) -> impl Future<Output = Result<(), Error>>
Read from the requested attribute and encode the result using the provided reply type.
Sourcefn bump_dataver(&self, ctx: impl MatchContext)
fn bump_dataver(&self, ctx: impl MatchContext)
Bump the per-cluster Dataver for the cluster handler matching
the supplied context endpoint_id / cluster_id.
Provided Methods§
Sourcefn read_awaits(&self, _ctx: impl ReadContext) -> bool
fn read_awaits(&self, _ctx: impl ReadContext) -> bool
Provide information whether the handler will internally await while reading the current value of the provided attribute.
Handlers which report false via this method provide an opportunity
for the Data Model processing to use less memory by not storing the incoming request
in an intermediate buffer.
The default implementation unconditionally returns true i.e. the handler is assumed to
await while reading any attribute.
Sourcefn write_awaits(&self, _ctx: impl WriteContext) -> bool
fn write_awaits(&self, _ctx: impl WriteContext) -> bool
Provide information whether the handler will internally await while updating the value of the provided attribute.
Handlers which report false via this method provide an opportunity
for the Data Model processing to use less memory by not storing the incoming request
in an intermediate buffer.
The default implementation unconditionally returns true i.e. the handler is assumed to
await while writing any attribute.
Sourcefn invoke_awaits(&self, _ctx: impl InvokeContext) -> bool
fn invoke_awaits(&self, _ctx: impl InvokeContext) -> bool
Provide information whether the handler will internally await while invoking the provided command.
Handlers which report false via this method provide an opportunity
for the Data Model processing to use less memory by not storing the incoming request
in an intermediate buffer.
The default implementation unconditionally returns true i.e. the handler is assumed to
await while invoking any command.
Sourcefn write(
&self,
_ctx: impl WriteContext,
) -> impl Future<Output = Result<(), Error>>
fn write( &self, _ctx: impl WriteContext, ) -> impl Future<Output = Result<(), Error>>
Write into the requested attribute using the provided data.
The default implementation errors out with ErrorCode::AttributeNotFound.
Sourcefn invoke(
&self,
_ctx: impl InvokeContext,
_reply: impl InvokeReply,
) -> impl Future<Output = Result<(), Error>>
fn invoke( &self, _ctx: impl InvokeContext, _reply: impl InvokeReply, ) -> impl Future<Output = Result<(), Error>>
Invoke the requested command with the provided data and encode the result using the provided reply type.
The default implementation errors out with ErrorCode::CommandNotFound.
Sourcefn lifecycle(
&self,
_ctx: impl HandlerContext,
_op: LifecycleOp,
) -> Result<(), Error>
fn lifecycle( &self, _ctx: impl HandlerContext, _op: LifecycleOp, ) -> Result<(), Error>
Process a lifecycle operation (LifecycleOp).
Unlike read/write/invoke - which are routed to the single handler matching the operation path - this method is invoked on every handler in the handler chain.
Deliberately synchronous - like AsyncHandler::bump_dataver -
even on the async handler trait, so that lifecycle broadcasts can
be dispatched eagerly from synchronous call sites (see
HandlerContext::notify_fabric_removed).
The default implementation does nothing.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".