Extractor

Trait Extractor 

Source
pub trait Extractor: 'static + Sized {
    // Required method
    fn extract(env: &Environment) -> Result<Self, Error>;
}
Expand description

A trait for extracting values from an Environment.

Types implementing this trait can be extracted from an Environment instance. This is useful for dependency injection and accessing shared resources.

Required Methods§

Source

fn extract(env: &Environment) -> Result<Self, Error>

Attempts to extract an instance of Self from the given environment.

§Errors

Returns an error if extraction fails, for example if the required value is not present in the environment.

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<T: Extractor> Extractor for Option<T>

Source§

fn extract(env: &Environment) -> Result<Self, Error>

Converts a regular extraction into an optional extraction.

This implementation allows for graceful handling of extraction failures by converting the error case into a None value.

Implementors§

Source§

impl Extractor for Environment

Source§

impl<T: 'static + Clone> Extractor for Use<T>