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>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;
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<Key<T>> for Key<T>where
T: Any,
impl<T> PartialEq<Key<T>> for Key<T>where T: Any,
source§impl<T> PartialOrd<Key<T>> for Key<T>where
T: Any,
impl<T> PartialOrd<Key<T>> 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 more