Skip to main content

config/
chained.rs

1use crate::{Configuration, Merge, Result, Settings};
2use std::sync::Arc;
3use tokens::ChangeToken;
4
5/// Represents a chained [configuration provider](crate::Provider).
6pub struct Provider(Arc<Configuration>);
7
8impl Provider {
9    /// Initializes a new chained configuration provider.
10    ///
11    /// # Arguments
12    ///
13    /// * `configuration` - The [configuration](Configuration) to chain
14    #[inline]
15    pub fn new(configuration: Arc<Configuration>) -> Self {
16        Self(configuration)
17    }
18}
19
20impl crate::Provider for Provider {
21    #[inline]
22    fn name(&self) -> &str {
23        "Chained"
24    }
25
26    #[inline]
27    fn reload_token(&self) -> Box<dyn ChangeToken> {
28        Box::new(self.0.change_token())
29    }
30
31    fn load(&self, settings: &mut Settings) -> Result {
32        settings.merge(&*self.0);
33        Ok(())
34    }
35}