pub struct Accessor<Component>(/* private fields */);
Expand description
Helper to give access to a component via a turbofish-friendly, infix syntax.
Implementations§
Source§impl<Component> Accessor<Component>
impl<Component> Accessor<Component>
Sourcepub fn from<'c, Container>(&self, container: &'c Container) -> &'c Componentwhere
Container: Has<Component>,
pub fn from<'c, Container>(&self, container: &'c Container) -> &'c Componentwhere
Container: Has<Component>,
Accesses a component from its container.
This function simply delegates to the trait’s method, but it might be interesting for those who prefer turbofish to annotate types combined with an infix notation.
Examples found in repository?
examples/env.rs (line 27)
16fn run_with<E>(env: E)
17where
18 E: Has<Host> + Has<Port> + Has<Verbosity>,
19{
20 // Accessing via trait-method + type annotation.
21 let host: &Host = env.access();
22
23 // Accessing via free-standing function + turbofish.
24 let port = access_from::<Port, _>(&env);
25
26 // Accessing via free-standing function + turbofish + infix.
27 let verbosity = access::<Verbosity>().from(&env);
28
29 println!(
30 "host: {:?}, port: {:?}, verbosity: {:?}",
31 host, port, verbosity
32 )
33}
Trait Implementations§
Auto Trait Implementations§
impl<Component> Freeze for Accessor<Component>
impl<Component> RefUnwindSafe for Accessor<Component>where
Component: RefUnwindSafe,
impl<Component> Send for Accessor<Component>where
Component: Send,
impl<Component> Sync for Accessor<Component>where
Component: Sync,
impl<Component> Unpin for Accessor<Component>where
Component: Unpin,
impl<Component> UnwindSafe for Accessor<Component>where
Component: UnwindSafe,
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