Skip to main content

serenade_di/
reference.rs

1//! Service reference used when declaring dependencies.
2
3/// Points at another service id in the container.
4#[derive(Clone, Debug, Eq, PartialEq, Hash)]
5pub struct Reference {
6    id: String,
7}
8
9impl Reference {
10    /// Creates a reference to `id`.
11    #[must_use]
12    pub fn new(id: impl Into<String>) -> Self {
13        Self { id: id.into() }
14    }
15
16    /// Referenced service id.
17    #[must_use]
18    pub fn id(&self) -> &str {
19        &self.id
20    }
21}
22
23impl From<&str> for Reference {
24    fn from(value: &str) -> Self {
25        Self::new(value)
26    }
27}
28
29impl From<String> for Reference {
30    fn from(value: String) -> Self {
31        Self::new(value)
32    }
33}