Struct error_stack::provider::Demand
source · [−]#[repr(transparent)]pub struct Demand<'a>(_);
Available on
nightly
only.Expand description
A helper object for providing data by type.
A data provider provides values by calling this type’s provide methods.
Implementations
sourceimpl<'a> Demand<'a>
impl<'a> Demand<'a>
sourcepub fn provide_value<T, F>(&mut self, fulfil: F) -> &mut Self where
T: 'static,
F: FnOnce() -> T,
pub fn provide_value<T, F>(&mut self, fulfil: F) -> &mut Self where
T: 'static,
F: FnOnce() -> T,
Provide a value or other type with only static lifetimes.
Examples
Provides a String
by cloning.
use error_stack::provider::{Demand, Provider};
impl Provider for SomeConcreteType {
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
demand.provide_value::<String, _>(|| self.field.clone());
}
}
sourcepub fn provide_ref<T: ?Sized + 'static>(&mut self, value: &'a T) -> &mut Self
pub fn provide_ref<T: ?Sized + 'static>(&mut self, value: &'a T) -> &mut Self
Provide a reference, note that the referee type must be bounded by 'static
,
but may be unsized.
Examples
Provides a reference to a field as a &str
.
use error_stack::provider::{Demand, Provider};
impl Provider for SomeConcreteType {
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
demand.provide_ref::<str>(&self.field);
}
}