Skip to main content

a3s_boot/provider/
token.rs

1use std::any::type_name;
2use std::fmt;
3
4/// Stable lookup key for an injectable provider.
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub struct ProviderToken(String);
7
8impl ProviderToken {
9    pub fn named(name: impl Into<String>) -> Self {
10        Self(name.into())
11    }
12
13    pub fn of<T>() -> Self
14    where
15        T: Send + Sync + 'static,
16    {
17        Self(type_name::<T>().to_string())
18    }
19
20    pub fn as_str(&self) -> &str {
21        &self.0
22    }
23}
24
25impl fmt::Display for ProviderToken {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        f.write_str(&self.0)
28    }
29}