fuel_core_services

Trait RunnableService

Source
pub trait RunnableService: Send {
    type SharedData: Clone + Send + Sync;
    type Task: RunnableTask;
    type TaskParams: Send;

    const NAME: &'static str;

    // Required methods
    fn shared_data(&self) -> Self::SharedData;
    fn into_task<'life0, 'async_trait>(
        self,
        state_watcher: &'life0 StateWatcher,
        params: Self::TaskParams,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Task>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait used by ServiceRunner to encapsulate the business logic tasks for a service.

Required Associated Constants§

Source

const NAME: &'static str

The name of the runnable service, used for namespacing error messages.

Required Associated Types§

Source

type SharedData: Clone + Send + Sync

Service specific shared data. This is used when you have data that needs to be shared by one or more tasks. It is the implementors responsibility to ensure cloning this type is shallow and doesn’t provide a full duplication of data that is meant to be shared between asynchronous processes.

Source

type Task: RunnableTask

The initialized runnable task type.

Source

type TaskParams: Send

Optional parameters used to when initializing into task.

Required Methods§

Source

fn shared_data(&self) -> Self::SharedData

A cloned instance of the shared data

Source

fn into_task<'life0, 'async_trait>( self, state_watcher: &'life0 StateWatcher, params: Self::TaskParams, ) -> Pin<Box<dyn Future<Output = Result<Self::Task>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Converts the service into a runnable task before the main run loop.

The state is a State watcher of the service. Some tasks may handle state changes on their own.

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§