Extract

Trait Extract 

Source
pub trait Extract<T> {
    // Required method
    fn extract(app: &AppBuilder) -> Result<T, AppError>;

    // Provided method
    fn dependencies() -> Dependencies { ... }
}
Expand description

Trait for extracting owned values from the application builder.

This trait allows extracting components or service handles from the application by value. The extracted value must implement Clone to be extracted this way.

§Type Parameters

  • T - The type to extract from the application.

§Examples

use diode::{AppBuilder, AppError, Extract};

struct ConfigExtractor;

impl Extract<String> for ConfigExtractor {
    fn extract(app: &AppBuilder) -> Result<String, AppError> {
        app.get_component::<String>()
            .ok_or(AppError::MissingDependency)
    }
}

Required Methods§

Source

fn extract(app: &AppBuilder) -> Result<T, AppError>

Extracts a value of type T from the application builder.

§Arguments
  • app - Reference to the application builder containing components.
§Returns

Returns Ok(T) if the component exists and can be extracted, or Err(AppError) if extraction fails.

Provided Methods§

Source

fn dependencies() -> Dependencies

Returns the dependencies required by this type.

The default implementation returns an empty dependencies set, indicating no dependencies are required.

§Returns

A Dependencies object describing required dependencies.

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§

Source§

impl<T> Extract<T> for Component
where T: Clone + Send + Sync + 'static,

Source§

impl<T, S> Extract<T> for S
where T: Clone + Send + Sync + 'static, S: Service<Handle = T> + 'static,