Skip to main content

di/
dependency.rs

1use crate::Type;
2
3/// Represents the possible cardinalities of a service dependency.
4#[derive(Copy, Clone, Debug, PartialEq)]
5pub enum ServiceCardinality {
6    /// Indicates a cardinality of zero or one (0:1).
7    ZeroOrOne,
8
9    /// Indicates a cardinality of exactly one (1:1).
10    ExactlyOne,
11
12    /// Indicates a cardinality of zero or more (0:*).
13    ZeroOrMore,
14}
15
16/// Represents a service dependency.
17#[derive(Clone, Debug, PartialEq)]
18pub struct ServiceDependency {
19    injected_type: Type,
20    cardinality: ServiceCardinality,
21}
22
23impl ServiceDependency {
24    /// Initializes a new service dependency.
25    ///
26    /// # Arguments
27    ///
28    /// * `injected_type` - The [injected type](Type) of the service dependency
29    /// * `cardinality` - The [cardinality](ServiceCardinality) of the service dependency
30    pub fn new(injected_type: Type, cardinality: ServiceCardinality) -> Self {
31        Self {
32            injected_type,
33            cardinality,
34        }
35    }
36
37    /// Gets the [injected type](Type) associated with the service dependency.
38    #[inline]
39    pub fn injected_type(&self) -> &Type {
40        &self.injected_type
41    }
42
43    /// Gets the [cardinality](ServiceCardinality) associated with the service dependency.
44    #[inline]
45    pub fn cardinality(&self) -> ServiceCardinality {
46        self.cardinality
47    }
48}