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