Skip to main content

options/prelude/
builder.rs

1mod configure;
2mod validate;
3
4use di::ServiceCollection;
5use std::marker::PhantomData;
6use std::ops::{Deref, DerefMut};
7
8/// Represents a builder used to configure options.
9pub struct Builder<'a, T: 'static> {
10    name: String,
11    services: &'a mut ServiceCollection,
12    _type: PhantomData<T>,
13}
14
15impl<'a, T: 'static> Builder<'a, T> {
16    /// Initializes a new options builder.
17    ///
18    /// # Arguments
19    ///
20    /// * `services` - The associated [collection of services](di::ServiceCollection)
21    /// * `name` - The optional name associated with the options
22    ///
23    /// # Remarks
24    ///
25    /// Names are matched using case-insensitive ASCII characters.
26    #[inline]
27    pub fn new(services: &'a mut ServiceCollection, name: &str) -> Self {
28        Self {
29            name: name.into(),
30            services,
31            _type: PhantomData,
32        }
33    }
34
35    /// Gets the name of the options
36    #[inline]
37    pub fn name(&self) -> &str {
38        &self.name
39    }
40
41    /// Gets the associated [collection of services](di::ServiceCollection)    
42    #[inline]
43    pub fn services(&mut self) -> &mut ServiceCollection {
44        self.services
45    }
46}
47
48impl<'a, T> From<Builder<'a, T>> for &'a mut ServiceCollection {
49    #[inline]
50    fn from(builder: Builder<'a, T>) -> Self {
51        builder.services
52    }
53}
54
55impl<'a, T> Deref for Builder<'a, T> {
56    type Target = ServiceCollection;
57
58    #[inline]
59    fn deref(&self) -> &Self::Target {
60        self.services
61    }
62}
63
64impl<'a, T> DerefMut for Builder<'a, T> {
65    #[inline]
66    fn deref_mut(&mut self) -> &mut Self::Target {
67        self.services
68    }
69}
70
71fn names_equal(name: &str, other_name: &str) -> bool {
72    name.len() == other_name.len() && name.eq_ignore_ascii_case(other_name)
73}