Trait zng::handler::AppHandler
source · pub trait AppHandler<A>: Any + Sendwhere
A: Clone + 'static,{
// Required method
fn event(&mut self, args: &A, handler_args: &AppHandlerArgs<'_>);
// Provided methods
fn boxed(self) -> Box<dyn AppHandler<A>>
where Self: Sized { ... }
fn cfg_boxed(self) -> Box<dyn AppHandler<A>>
where Self: Sized { ... }
}
Expand description
Represents an event handler in the app context.
There are different flavors of handlers, you can use macros to declare then.
See app_hn!
, app_hn_once!
or async_app_hn!
, async_app_hn_once!
to start.
Required Methods§
sourcefn event(&mut self, args: &A, handler_args: &AppHandlerArgs<'_>)
fn event(&mut self, args: &A, handler_args: &AppHandlerArgs<'_>)
Called every time the event happens.
The handler_args
can be used to unsubscribe the handler. Async handlers are expected to schedule
their tasks to run somewhere in the app, usually in the UPDATES.on_update
. The handle
is
not expected to cancel running async tasks, only to drop self
before the next event happens.
Provided Methods§
sourcefn boxed(self) -> Box<dyn AppHandler<A>>where
Self: Sized,
fn boxed(self) -> Box<dyn AppHandler<A>>where
Self: Sized,
Boxes the handler.
The type Box<dyn AppHandler<A>>
implements AppHandler<A>
and just returns itself
in this method, avoiding double boxing.
sourcefn cfg_boxed(self) -> Box<dyn AppHandler<A>>where
Self: Sized,
fn cfg_boxed(self) -> Box<dyn AppHandler<A>>where
Self: Sized,
Boxes the handler if the feature = "dyn_closure"
is enabled, otherwise maintain the same type.