pub struct RuleBasedLoader { /* private fields */ }👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API
Expand description
Configuration loader with rule-based discovery.
Provides advanced configuration loading with support for:
- Rule-based file discovery
- Multi-tier configuration merging
- Fragment (conf.d) loading
- Custom merge strategies
§Example
use cfgmatic_files::RuleBasedLoader;
use cfgmatic_paths::{ConfigRuleSet, ConfigFileRule, TierSearchMode};
use cfgmatic_merge::MergeBehavior;
let rules = ConfigRuleSet::builder()
.main_file(ConfigFileRule::toml("config")
.tiers(TierSearchMode::All)
.required(true))
.build();
let loader = RuleBasedLoader::new("myapp")
.rules(rules)
.merge_behavior(MergeBehavior::Deep);
// Load with discovery info
match loader.load_with_discovery::<serde_json::Value>() {
Ok((config, discovery)) => {
println!("Loaded from {} files", discovery.file_count());
}
Err(e) => eprintln!("Error: {}", e),
}Implementations§
Source§impl RuleBasedLoader
impl RuleBasedLoader
Sourcepub fn new(app_name: impl Into<String>) -> Self
👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API
pub fn new(app_name: impl Into<String>) -> Self
Create a new loader for an application.
Sourcepub fn rules(self, rules: ConfigRuleSet) -> Self
👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API
pub fn rules(self, rules: ConfigRuleSet) -> Self
Set the rule set for file discovery.
Sourcepub fn merge_behavior(self, behavior: MergeBehavior) -> Self
👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API
pub fn merge_behavior(self, behavior: MergeBehavior) -> Self
Set the merge behavior.
Sourcepub const fn array_strategy(self, strategy: ArrayMergeStrategy) -> Self
👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API
pub const fn array_strategy(self, strategy: ArrayMergeStrategy) -> Self
Set the array merge strategy.
Sourcepub const fn merge_options(self, options: MergeOptions) -> Self
👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API
pub const fn merge_options(self, options: MergeOptions) -> Self
Set full merge options.
Sourcepub fn load_with_discovery<T>(&self) -> Result<(T, RuleBasedDiscovery)>
👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API
pub fn load_with_discovery<T>(&self) -> Result<(T, RuleBasedDiscovery)>
Load configuration with discovery information.
§Errors
Returns an error if:
- Required files are not found
- Files cannot be read or parsed
- Merge fails in Error mode with conflicts
§Example
use cfgmatic_files::RuleBasedLoader;
let loader = RuleBasedLoader::new("myapp");
match loader.load_with_discovery::<serde_json::Value>() {
Ok((config, discovery)) => {
println!("Loaded config: {:#}", config);
for path in discovery.all_paths() {
println!(" - {}", path.display());
}
}
Err(e) => eprintln!("Error: {}", e),
}Trait Implementations§
Source§impl Clone for RuleBasedLoader
impl Clone for RuleBasedLoader
Source§fn clone(&self) -> RuleBasedLoader
fn clone(&self) -> RuleBasedLoader
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RuleBasedLoader
impl RefUnwindSafe for RuleBasedLoader
impl Send for RuleBasedLoader
impl Sync for RuleBasedLoader
impl Unpin for RuleBasedLoader
impl UnsafeUnpin for RuleBasedLoader
impl UnwindSafe for RuleBasedLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more