pub trait AppHandler<A: Clone + 'static>: Any + Send {
// 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.