Skip to main content

Service

Trait Service 

Source
pub trait Service:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn schedule(&self) -> Schedule;
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 ServiceContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), ServiceError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn start<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 ServiceContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), ServiceError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn stop<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Work a ServiceHost runs in the background.

Required Methods§

Source

fn name(&self) -> &str

Source

fn schedule(&self) -> Schedule

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 ServiceContext, ) -> Pin<Box<dyn Future<Output = Result<(), ServiceError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Provided Methods§

Source

fn start<'life0, 'life1, 'async_trait>( &'life0 self, _ctx: &'life1 ServiceContext, ) -> Pin<Box<dyn Future<Output = Result<(), ServiceError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Once, before any service’s first run. A failure is reported and the service still runs.

Source

fn stop<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Once, after the host has drained.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<F, Fut> Service for FnService<F>
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), ServiceError>> + Send + 'static,