Service

Trait Service 

Source
pub trait Service:
    Sized
    + Send
    + Sync
    + 'static {
    type Message: Send + 'static;
    type ClientMethods: ClientMethods<Self>;

    // Required methods
    fn create(app: &App) -> Self;
    fn handle(
        self: Arc<Self>,
        msg: Self::Message,
    ) -> impl Future<Output = ()> + Send;

    // Provided methods
    fn startup(self: Arc<Self>) -> impl Future<Output = ()> + Send { ... }
    fn shutdown(self: Arc<Self>) -> impl Future<Output = ()> + Send { ... }
}

Required Associated Types§

Required Methods§

Source

fn create(app: &App) -> Self

Sync creation - for dependency injection

Source

fn handle( self: Arc<Self>, msg: Self::Message, ) -> impl Future<Output = ()> + Send

Message handler

Provided Methods§

Source

fn startup(self: Arc<Self>) -> impl Future<Output = ()> + Send

Async initialization - runs after create, before workers start receiving messages. Default: no-op.

Note: Cannot call other services here - workers aren’t running yet.

Source

fn shutdown(self: Arc<Self>) -> impl Future<Output = ()> + Send

Cleanup - runs on shutdown, before channels close. Default: no-op.

Note: Can call other services - workers are still running.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§