pub struct ServiceKey(/* private fields */);Expand description
Key used by keyed registrations, including the AnyKey fallback sentinel.
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) -> ServiceKey
pub fn new<T>(value: T) -> ServiceKey
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() -> ServiceKey
pub fn any_key() -> ServiceKey
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.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Borrow the key as &str for string-like keys: String and
&'static str (including ServiceKey::new("literal")). Returns None
for other typed keys and the AnyKey sentinel.
This is the compatibility bridge used by the default
IServiceResolver typed-key methods, which fall back to the legacy
string methods. Note that the fallback maps a typed &'static str key to
a String key; in fully typed containers those two keys are not
equal, so typed-key consumers should use the *_key methods.
Trait Implementations§
Source§impl Clone for ServiceKey
impl Clone for ServiceKey
Source§fn clone(&self) -> ServiceKey
fn clone(&self) -> ServiceKey
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more