Skip to main content

qubit_config/source/
config_source.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026.
4 *    Haixing Hu, Qubit Co. Ltd.
5 *
6 *    All rights reserved.
7 *
8 ******************************************************************************/
9use crate::{Config, ConfigResult};
10
11/// Trait for configuration sources
12///
13/// Implementors of this trait can load configuration data and populate a
14/// [`Config`] object.
15///
16/// # Examples
17///
18/// ```rust,ignore
19/// use qubit_config::{Config, source::ConfigSource};
20///
21/// struct MySource;
22///
23/// impl ConfigSource for MySource {
24///     fn load(&self, config: &mut Config) -> qubit_config::ConfigResult<()> {
25///         config.set("key", "value")?;
26///         Ok(())
27///     }
28/// }
29/// ```
30///
31/// # Author
32///
33/// Haixing Hu
34pub trait ConfigSource {
35    /// Loads configuration data into the provided `Config` object
36    ///
37    /// # Parameters
38    ///
39    /// * `config` - The configuration object to populate
40    ///
41    /// # Returns
42    ///
43    /// Returns `Ok(())` on success, or a `ConfigError` on failure
44    fn load(&self, config: &mut Config) -> ConfigResult<()>;
45}