Skip to main content

RuleBasedLoader

Struct RuleBasedLoader 

Source
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

Source

pub 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

Create a new loader for an application.

Source

pub fn rules(self, rules: ConfigRuleSet) -> Self

👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API

Set the rule set for file discovery.

Source

pub fn merge_behavior(self, behavior: MergeBehavior) -> Self

👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API

Set the merge behavior.

Source

pub 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

Set the array merge strategy.

Source

pub 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

Set full merge options.

Source

pub 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

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),
}
Source

pub fn load<T>(&self) -> Result<T>

👎Deprecated since 2.0.1: use cfgmatic-source crate instead, which provides a unified configuration source API

Load configuration (without discovery info).

§Errors

Returns an error if configuration cannot be loaded.

Trait Implementations§

Source§

impl Clone for RuleBasedLoader

Source§

fn clone(&self) -> RuleBasedLoader

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RuleBasedLoader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.