Skip to main content

Handler

Trait Handler 

Source
pub trait Handler<T: ?Sized>: 'static {
    // Required methods
    fn id(&self) -> Ustr;
    fn handle(&self, message: &T);
}
Expand description

Compile-time type-safe message handler trait.

Provides zero-cost dispatch for statically typed messages. Can also be used with dyn Any for dynamic dispatch when type flexibility is needed.

Required Methods§

Source

fn id(&self) -> Ustr

Returns the unique identifier for this handler.

Source

fn handle(&self, message: &T)

Handles a message of type T.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: ?Sized, H: Handler<T>> Handler<T> for Rc<H>

Source§

fn id(&self) -> Ustr

Source§

fn handle(&self, message: &T)

Implementors§

Source§

impl Handler<dyn Any> for CallCheckHandler

Source§

impl Handler<dyn Any> for PyCallableHandler

Source§

impl Handler<dyn Any> for StubMessageHandler

Source§

impl<T: 'static, F: Fn(&T) + 'static> Handler<T> for CallbackHandler<T, F>

Source§

impl<T: Clone + 'static> Handler<T> for TypedMessageSavingHandler<T>

Source§

impl<T: Clone + 'static> Handler<dyn Any> for AnySavingHandler<T>