Struct runa_core::provide_any::Demand
source · #[repr(transparent)]pub struct Demand<'a>(_);
Implementations§
source§impl<'a> Demand<'a>
impl<'a> Demand<'a>
sourcepub fn provide_value<T, F>(&mut self, fulfil: F) -> &mut Selfwhere
T: 'static,
F: FnOnce() -> T,
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());
}
}
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 std::any::{Demand, Provider};
impl Provider for SomeConcreteType {
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
demand.provide_ref::<str>(&self.field);
}
}
pub fn provide_mut<T: ?Sized + 'static>( &mut self, value: &'a mut T ) -> &mut Self
sourcepub fn maybe_provide_mut<T: ?Sized + 'static>(
&mut self
) -> Option<Receiver<'a, '_, RefMut<MaybeSizedValue<T>>>>
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.