ApplicationPart

Trait ApplicationPart 

Source
pub trait ApplicationPart {
    type Error: Error + Send;

    // Required method
    fn run(
        &mut self,
        cancellation_token: CancellationToken,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send + '_;

    // Provided methods
    fn name() -> Cow<'static, str> { ... }
    fn before_startup(
        &mut self,
        cancellation_token: CancellationToken,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send + '_ { ... }
    fn before_shutdown(
        &mut self,
        cancellation_token: CancellationToken,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send + '_ { ... }
}
Expand description

Trait representing a part of an application lifecycle.

Implementors define async hooks for startup, running, and shutdown phases. All hooks should return immediately if cancelled via the provided CancellationToken. Hooks are run in parallel for all parts.

Required Associated Types§

Source

type Error: Error + Send

The error type returned by this application part’s hooks.

Required Methods§

Source

fn run( &mut self, cancellation_token: CancellationToken, ) -> impl Future<Output = Result<(), Self::Error>> + Send + '_

Runs the main logic for this application part.

§Arguments
  • cancellation_token - A token that can be used to cancel execution. If cancelled, this function should return immediately and not error.
§Returns

A future that resolves to Result<(), Self::Error>.

Provided Methods§

Source

fn name() -> Cow<'static, str>

Returns the name of this application part as a string.

§Returns

A Cow<str> containing the type name of the application part. By default, this is the Rust type name, but can be overridden for custom display.

Source

fn before_startup( &mut self, cancellation_token: CancellationToken, ) -> impl Future<Output = Result<(), Self::Error>> + Send + '_

Called before application startup for this part.

§Arguments
  • cancellation_token - A token that can be used to cancel startup. If cancelled, this function should return immediately and not error.
§Returns

A future that resolves to Result<(), Self::Error>.

Source

fn before_shutdown( &mut self, cancellation_token: CancellationToken, ) -> impl Future<Output = Result<(), Self::Error>> + Send + '_

Called before application shutdown for this part.

§Arguments
  • cancellation_token - A token that can be used to cancel execution. If cancelled, this function should return immediately and not error.
§Returns

A future that resolves to Result<(), Self::Error>. Should not block for too long.

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.

Implementations on Foreign Types§

Source§

impl ApplicationPart for ()

Source§

type Error = Infallible

Source§

async fn run( &mut self, _cancellation_token: CancellationToken, ) -> Result<(), Self::Error>

Implementors§

Source§

impl<Head, Tail> ApplicationPart for Node<Head, Tail>
where Head: ApplicationPart + Send + Sync, Tail: ApplicationPart + Send + Sync,