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§
source§impl<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>
pub fn tagged<K>(tag: K) -> Result<Self, Error>
Construct a new key.
Examples
use serde::Serialize;
use async_injector::Key;
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§
source§impl<T> Ord for Key<T>where
T: Any,
impl<T> Ord for Key<T>where
T: Any,
source§impl<T> PartialEq for Key<T>where
T: Any,
impl<T> PartialEq for Key<T>where
T: Any,
source§impl<T> PartialOrd for Key<T>where
T: Any,
impl<T> PartialOrd for Key<T>where
T: Any,
1.0.0 · source§fn 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 moreimpl<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§
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