Skip to main content

Handler

Trait Handler 

Source
pub trait Handler:
    Send
    + Sync
    + 'static {
    // Required method
    fn handle<'life0, 'async_trait>(
        &'life0 self,
        msg: CanonicalMessage,
    ) -> Pin<Box<dyn Future<Output = Result<Handled, HandlerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn handle_many<'life0, 'async_trait>(
        &'life0 self,
        msgs: Vec<CanonicalMessage>,
    ) -> Pin<Box<dyn Future<Output = Vec<Result<Handled, HandlerError>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn register_handler(
        &self,
        _type_name: &str,
        _handler: Arc<dyn Handler>,
    ) -> Option<Arc<dyn Handler>> { ... }
}
Expand description

A generic trait for handling messages (commands or events).

Handlers process an incoming message and can optionally return a new message (e.g. a reply) via Handled::Publish, or acknowledge processing via Handled::Ack.

Required Methods§

Source

fn handle<'life0, 'async_trait>( &'life0 self, msg: CanonicalMessage, ) -> Pin<Box<dyn Future<Output = Result<Handled, HandlerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Provided Methods§

Source

fn handle_many<'life0, 'async_trait>( &'life0 self, msgs: Vec<CanonicalMessage>, ) -> Pin<Box<dyn Future<Output = Vec<Result<Handled, HandlerError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn register_handler( &self, _type_name: &str, _handler: Arc<dyn Handler>, ) -> Option<Arc<dyn Handler>>

Tries to register a handler for a specific type. Returns None if this handler does not support registration (e.g. it’s not a TypeHandler).

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: Handler + ?Sized> Handler for Arc<T>

Source§

fn handle<'life0, 'async_trait>( &'life0 self, msg: CanonicalMessage, ) -> Pin<Box<dyn Future<Output = Result<Handled, HandlerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn handle_many<'life0, 'async_trait>( &'life0 self, msgs: Vec<CanonicalMessage>, ) -> Pin<Box<dyn Future<Output = Vec<Result<Handled, HandlerError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn register_handler( &self, type_name: &str, handler: Arc<dyn Handler>, ) -> Option<Arc<dyn Handler>>

Implementors§

Source§

impl Handler for TypeHandler

Source§

impl<F, Fut> Handler for F
where F: Fn(CanonicalMessage) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Handled, HandlerError>> + Send,

Source§

impl<T: AsyncHandler> Handler for SimpleHandler<T>