Skip to main content

service_fn

Function service_fn 

Source
pub fn service_fn<C, F, Fut, O>(name: &'static str, run: F) -> FnService<C, F>
where C: Clone + Send + Sync + 'static, F: Fn(Context<C>) -> Fut + Send + Sync + 'static, Fut: Future<Output = O> + Send + 'static, O: IntoServiceOutcome + Send + 'static,
Expand description

Wraps an async function as a SupervisedService.

This keeps one-off services ergonomic without widening the core trait surface or forcing callers into a monolithic service object pattern.

The resulting service can be registered with SupervisorBuilder::add or SupervisorBuilder::add_with_options.

The closure’s Context parameter determines the extracted service context. With a stateful builder, that usually means:

  • Context<AppState> when the service wants the full root state
  • Context<Subset> when Subset: FromSupervisorState<AppState>