Struct Scope

Source
pub struct Scope {
    pub registry: Arc<SupplierRegistry>,
}

Fields§

§registry: Arc<SupplierRegistry>

Implementations§

Source§

impl Scope

Source

pub async fn demand<T: Send + 'static>( &self, demand: Demand, input: Box<dyn Any + Send>, ) -> T

Examples found in repository?
examples/demo.rs (line 46)
38    async fn supply(&self, _input: (), scope: Arc<Scope>) -> i32 {
39        // Construct override registry using its internally owned alt supplier
40        let mut overrides = SupplierRegistry::new();
41        overrides.insert("valueA".to_string(), self.alt.clone());
42        let demand = Demand {
43            type_: "valueA".to_string(),
44            override_suppliers: Some(overrides),
45        };
46        let va: i32 = scope.demand(demand, Box::new(())).await;
47        va + 5
48    }
49}
50
51impl ValueBSupplier {
52    /// Convenience constructor to bundle the alt supplier privately
53    fn new() -> Self {
54        Self {
55            alt: Arc::new(AltValueASupplier),
56        }
57    }
58}
59
60/// The root supplier, asks for valueA and valueB, combines results.
61struct RootSupplier;
62#[async_trait]
63impl Supplier for RootSupplier {
64    type Input = ();
65    type Output = i32;
66    async fn supply(&self, _input: (), scope: Arc<Scope>) -> i32 {
67        let va: i32 = scope
68            .demand(
69                Demand {
70                    type_: "valueA".to_string(),
71                    override_suppliers: None,
72                },
73                Box::new(()),
74            )
75            .await;
76        let vb: i32 = scope
77            .demand(
78                Demand {
79                    type_: "valueB".to_string(),
80                    override_suppliers: None,
81                },
82                Box::new(()),
83            )
84            .await;
85        va + vb
86    }

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl !RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl !UnwindSafe for Scope

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.