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§
Sourcefn enabled(
&self,
global: &Arc<Global>,
) -> impl Future<Output = Result<bool>> + Send
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.
Sourcefn run(
self,
global: Arc<Global>,
ctx: Context,
) -> impl Future<Output = Result<()>> + Send + 'static
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.
Note: Adding the
scuffle_signal::SignalSvc
service to the list of services when calling main
will
cancel the context as soon as a shutdown signal is received.
§See Also
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.