Struct async_injector::Key
source · [−]pub struct Key<T> where
T: Any, { /* private fields */ }
Expand description
A key used to discriminate a value in the Injector.
Implementations
sourceimpl<T> Key<T> where
T: Any,
impl<T> Key<T> where
T: Any,
sourcepub fn of() -> Self
pub fn of() -> Self
Construct a new key without a tag.
Examples
use async_injector::Key;
struct Foo;
assert_eq!(Key::<Foo>::of(), Key::<Foo>::of());
sourcepub fn tagged<K>(tag: K) -> Result<Self, Error> where
K: Any + Serialize,
pub fn tagged<K>(tag: K) -> Result<Self, Error> where
K: Any + Serialize,
Construct a new key.
Examples
use serde::Serialize;
use async_injector::Key;
use std::error::Error;
struct Foo;
#[derive(Serialize)]
enum Tag {
One,
Two,
}
#[derive(Serialize)]
enum Tag2 {
One,
Two,
}
assert_eq!(Key::<Foo>::tagged(Tag::One)?, Key::<Foo>::tagged(Tag::One)?);
assert_ne!(Key::<Foo>::tagged(Tag::One)?, Key::<Foo>::tagged(Tag::Two)?);
assert_ne!(Key::<Foo>::tagged(Tag::One)?, Key::<Foo>::tagged(Tag2::One)?);
Trait Implementations
sourceimpl<T> Ord for Key<T> where
T: Any,
impl<T> Ord for Key<T> where
T: Any,
sourceimpl<T> PartialOrd<Key<T>> for Key<T> where
T: Any,
impl<T> PartialOrd<Key<T>> for Key<T> where
T: Any,
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T> Eq for Key<T> where
T: Any,
Auto Trait Implementations
impl<T> RefUnwindSafe for Key<T> where
T: RefUnwindSafe,
impl<T> Send for Key<T> where
T: Send,
impl<T> Sync for Key<T> where
T: Sync,
impl<T> Unpin for Key<T> where
T: Unpin,
impl<T> UnwindSafe for Key<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more