pub trait ExtractRef<T> {
// Required method
fn extract_ref(app: &AppBuilder) -> Result<&T, AppError>;
// Provided method
fn dependencies() -> Dependencies { ... }
}Expand description
Trait for extracting borrowed references from the application builder.
This trait allows extracting components or service handles from the application by reference, avoiding the need for cloning. This is more efficient when you only need to read from the component.
§Type Parameters
T- The type to extract a reference to from the application.
§Examples
use diode::{AppBuilder, AppError, ExtractRef};
struct ConfigExtractor;
impl ExtractRef<String> for ConfigExtractor {
fn extract_ref<'a>(app: &'a AppBuilder) -> Result<&'a String, AppError> {
app.get_component_ref::<String>()
.ok_or(AppError::MissingDependency)
}
}Required Methods§
Sourcefn extract_ref(app: &AppBuilder) -> Result<&T, AppError>
fn extract_ref(app: &AppBuilder) -> Result<&T, AppError>
Provided Methods§
Sourcefn dependencies() -> Dependencies
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.