Trait zng::handler::AppHandler

source ·
pub trait AppHandler<A>: Any + Send
where 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§

source

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§

source

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.

source

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.

Trait Implementations§

source§

impl<A> AppHandler<A> for Box<dyn AppHandler<A>>
where A: Clone + 'static,

source§

fn event(&mut self, args: &A, handler_args: &AppHandlerArgs<'_>)

Called every time the event happens. Read more
source§

fn boxed(self) -> Box<dyn AppHandler<A>>

Boxes the handler. Read more
source§

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.

Implementations on Foreign Types§

source§

impl<A> AppHandler<A> for Box<dyn AppHandler<A>>
where A: Clone + 'static,

source§

fn event(&mut self, args: &A, handler_args: &AppHandlerArgs<'_>)

source§

fn boxed(self) -> Box<dyn AppHandler<A>>

Implementors§

source§

impl<A, H, F> AppHandler<A> for FilterAppHandler<A, H, F>
where A: Clone + 'static, H: AppHandler<A>, F: FnMut(&A) -> bool + Send + 'static,