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§
Required Associated Types§
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.
Sourcetype Task: RunnableTask
type Task: RunnableTask
The initialized runnable task type.
Sourcetype TaskParams: Send
type TaskParams: Send
Optional parameters used to when initializing into task.
Required Methods§
A cloned instance of the shared data
Sourcefn 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,
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.