pub struct Scope {
pub registry: Arc<SupplierRegistry>,
}Fields§
§registry: Arc<SupplierRegistry>Implementations§
Source§impl Scope
impl Scope
Sourcepub async fn demand<T: Send + 'static>(
&self,
demand: Demand,
input: Box<dyn Any + Send>,
) -> T
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more