Skip to main content

config/
typed.rs

1use crate::{ser, Settings};
2use serde::Serialize;
3
4/// Represents a [configuration provider](crate::Provider) that serializes a [serializable](Serialize) as a set of
5/// configuration key/ pairs.
6pub struct Provider<T: Serialize>(T);
7
8impl<T: Serialize> Provider<T> {
9    /// Initializes a new typed configuration provider.
10    ///
11    /// # Arguments
12    ///
13    /// * `value` - The `Serialize`-able value to use as a configuration source
14    #[inline]
15    pub fn new(value: T) -> Self {
16        Self(value)
17    }
18}
19
20impl<T: Serialize + Send + Sync> crate::Provider for Provider<T> {
21    #[inline]
22    fn name(&self) -> &str {
23        "Typed"
24    }
25
26    fn load(&self, settings: &mut Settings) -> crate::Result {
27        ser::into(&self.0, settings)?;
28        Ok(())
29    }
30}