#[repr(transparent)]
pub struct Demand<'a>(_);

Implementations§

source§

impl<'a> Demand<'a>

source

pub fn provide_value<T, F>(&mut self, fulfil: F) -> &mut Selfwhere T: 'static, F: FnOnce() -> T,

Provide a value or other type with only static lifetimes.

Examples

Provides a String by cloning.

use std::any::{Demand, Provider};

impl Provider for SomeConcreteType {
    fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
        demand.provide_value::<String, _>(|| self.field.clone());
    }
}
source

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 std::any::{Demand, Provider};

impl Provider for SomeConcreteType {
    fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
        demand.provide_ref::<str>(&self.field);
    }
}
source

pub fn provide_mut<T: ?Sized + 'static>( &mut self, value: &'a mut T ) -> &mut Self

source

pub fn maybe_provide_mut<T: ?Sized + 'static>( &mut self ) -> Option<Receiver<'a, '_, RefMut<MaybeSizedValue<T>>>>

Provide a mutable references. But first check if T will be accepted.

This is because provide_mut takes a &'a mut T, which means once you called that, you won’t be able to provide anything else. Because it’s not possible to have multiple mutable references.

This method breaks up the process into two steps, first you check if T will be accepted, and you only pass the &'a mut T only if it will be accepted.

Trait Implementations§

source§

impl Debug for Demand<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Demand<'a>

§

impl<'a> !Send for Demand<'a>

§

impl<'a> !Sized for Demand<'a>

§

impl<'a> !Sync for Demand<'a>

§

impl<'a> !Unpin for Demand<'a>

§

impl<'a> !UnwindSafe for Demand<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more