pub struct ServiceKey(/* private fields */);Expand description
Key of a keyed service registration / resolution.
Construct a value key with ServiceKey::new (or From<&str>/From<String>
for string keys), and the fallback sentinel with ServiceKey::any_key.
§String keys
String-keyed registration APIs (keyed_singleton("name", …)) store the key
as a String. Use ServiceKey::from("name") / "name".into() to build an
equal key. ServiceKey::new("name") is a different key type (&str),
because key equality includes the value type — use it only for intentional
&'static str-typed keys.
§Reading a requested key
AnyKey fallback factories receive &ServiceKey. The erased key exposes
Debug/Display and equality/hash; there is intentionally no typed
downcast accessor (operations must be expressible through the ServiceKey
API itself, keeping the erased-key representation private).
Implementations§
Source§impl ServiceKey
impl ServiceKey
Sourcepub fn new<T>(value: T) -> Self
pub fn new<T>(value: T) -> Self
Create a typed key value.
use rust_dix::ServiceKey;
#[derive(Debug, PartialEq, Eq, Hash)]
enum Db { Read, Write }
let key = ServiceKey::new(Db::Read);
assert_ne!(key, ServiceKey::new(Db::Write));Sourcepub fn any_key() -> Self
pub fn any_key() -> Self
The AnyKey fallback sentinel (MEDI KeyedService.AnyKey).
Registering a service under this key makes it a fallback for every
key that has no exact registration. Resolving a single service with
this sentinel is not allowed (use ServiceKey-keyed lookups or
enumeration instead).
Sourcepub fn is_any(&self) -> bool
pub fn is_any(&self) -> bool
Whether this key is the ServiceKey::any_key sentinel.