Skip to main content

Provision

Struct Provision 

Source
pub struct Provision<'a, C: Capability> { /* private fields */ }
Expand description

A capability implementation associated with the module that supplies it.

This is a graph relationship, not a provider base class. The value may be borrowed from an object owned and constructed by the application.

Implementations§

Source§

impl<'a, C: Capability> Provision<'a, C>

Source

pub fn new(module: ModuleId, value: &'a C::Value) -> Self

Associates a module identity with a value implementing capability C.

Examples found in repository?
examples/02-resolution.rs (lines 50-53)
48fn main() -> Result<(), Box<dyn std::error::Error>> {
49    let system_clock = WallClock;
50    let only_system_clock = [Provision::<ClockCapability>::new(
51        SYSTEM_CLOCK,
52        &system_clock as &dyn Clock,
53    )];
54    let clock = Resolver::resolve::<ClockCapability>(GREETER, &only_system_clock, None)?;
55    println!("{}", Greeter::new(clock).greet("world"));
56
57    let test_clock = FixedClock(UNIX_EPOCH + Duration::from_secs(42));
58    let both_clocks = [
59        Provision::<ClockCapability>::new(SYSTEM_CLOCK, &system_clock as &dyn Clock),
60        Provision::<ClockCapability>::new(TEST_CLOCK, &test_clock as &dyn Clock),
61    ];
62    let clock = Resolver::resolve::<ClockCapability>(GREETER, &both_clocks, Some(TEST_CLOCK))?;
63    println!("{}", Greeter::new(clock).greet("Ada"));
64    Ok(())
65}
Source

pub fn from_module<M: Provides<C>>(module: &'a M) -> Self

Creates a provision from a module’s additive Provides contract.

Source

pub const fn module(&self) -> ModuleId

Returns the module identity associated with this provision.

Source

pub const fn value(&self) -> &'a C::Value

Returns the provided capability value.

Auto Trait Implementations§

§

impl<'a, C> Freeze for Provision<'a, C>
where &'a <C as Capability>::Value: Freeze,

§

impl<'a, C> RefUnwindSafe for Provision<'a, C>
where &'a <C as Capability>::Value: RefUnwindSafe,

§

impl<'a, C> Send for Provision<'a, C>
where &'a <C as Capability>::Value: Send,

§

impl<'a, C> Sync for Provision<'a, C>
where &'a <C as Capability>::Value: Sync,

§

impl<'a, C> Unpin for Provision<'a, C>
where &'a <C as Capability>::Value: Unpin,

§

impl<'a, C> UnsafeUnpin for Provision<'a, C>
where &'a <C as Capability>::Value: UnsafeUnpin,

§

impl<'a, C> UnwindSafe for Provision<'a, C>
where &'a <C as Capability>::Value: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.