Accessor

Struct Accessor 

Source
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>

Source

pub fn from<'c, Container>(&self, container: &'c Container) -> &'c Component
where 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§

Source§

impl<Component: Debug> Debug for Accessor<Component>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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.