Skip to main content

ServiceKey

Struct ServiceKey 

Source
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

Source

pub fn new<T>(value: T) -> ServiceKey
where T: Any + Send + Sync + Eq + Hash + Debug + 'static,

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));
Source

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).

Source

pub fn is_any(&self) -> bool

Whether this key is the ServiceKey::any_key sentinel.

Source

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

Source§

fn clone(&self) -> ServiceKey

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServiceKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for ServiceKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for ServiceKey

Source§

impl From<&ServiceKey> for ServiceKey

Source§

fn from(value: &ServiceKey) -> ServiceKey

Converts to this type from the input type.
Source§

impl From<&String> for ServiceKey

Source§

fn from(value: &String) -> ServiceKey

Converts to this type from the input type.
Source§

impl From<&str> for ServiceKey

Source§

fn from(value: &str) -> ServiceKey

Converts to this type from the input type.
Source§

impl From<String> for ServiceKey

Source§

fn from(value: String) -> ServiceKey

Converts to this type from the input type.
Source§

impl Hash for ServiceKey

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ServiceKey

Source§

fn eq(&self, other: &ServiceKey) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.