Trait Service

Source
pub trait Service<Global>:
    Send
    + Sync
    + 'static
    + Sized {
    // Provided methods
    fn name(&self) -> Option<&'static str> { ... }
    fn enabled(
        &self,
        global: &Arc<Global>,
    ) -> impl Future<Output = Result<bool>> + Send { ... }
    fn run(
        self,
        global: Arc<Global>,
        ctx: Context,
    ) -> impl Future<Output = Result<()>> + Send + 'static { ... }
}
Expand description

A service that can be run.

This trait is used to define a service that can be run in parallel to other services.

§See Also

Provided Methods§

Source

fn name(&self) -> Option<&'static str>

Returns the name of the service, if any.

Source

fn enabled( &self, global: &Arc<Global>, ) -> impl Future<Output = Result<bool>> + Send

Initialize the service and return Ok(true) if the service should be run.

Source

fn run( self, global: Arc<Global>, ctx: Context, ) -> impl Future<Output = Result<()>> + Send + 'static

Run the service. This function should return a future that is pending as long as the service is running. When the service finishes without any errors, the future should resolve to Ok(()). As a best practice, the service should stop as soon as the provided context is done.

§See Also
  • [scuffle_context::Context]

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§

Source§

impl<G, F, Fut> Service<G> for F
where F: FnOnce(Arc<G>, Context) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<()>> + Send + 'static,