Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

The main configuration container

Config provides lazy resolution of interpolation expressions and caches resolved values for efficiency.

Implementations§

Source§

impl Config

Source

pub fn new(value: Value) -> Self

Create a new Config from a Value

The config will use resolvers from the global registry.

Source

pub fn with_options(value: Value, options: ConfigOptions) -> Self

Create a Config with custom options

The config will use resolvers from the global registry.

Source

pub fn with_resolvers(value: Value, resolvers: ResolverRegistry) -> Self

Create a Config with a custom resolver registry

Source

pub fn from_yaml(yaml: &str) -> Result<Self>

Load configuration from a YAML string

Source

pub fn from_yaml_with_options( yaml: &str, options: ConfigOptions, ) -> Result<Self>

Load configuration from a YAML string with options

Source

pub fn load(path: impl AsRef<Path>) -> Result<Self>

Load configuration from a YAML file (required - errors if missing)

This is the primary way to load configuration. Use Config::optional() for files that may not exist.

Supports glob patterns like config/*.yaml or config/**/*.yaml. When a glob pattern is used, matching files are sorted alphabetically and merged in order (later files override earlier ones).

§Example
let config = Config::load("config.yaml")?;
let merged = Config::load("config/*.yaml")?;
Source

pub fn load_with_options( path: impl AsRef<Path>, options: ConfigOptions, ) -> Result<Self>

Load a configuration file with custom options

This is the main entry point for loading config with HTTP/TLS/proxy options. Supports glob patterns like config/*.yaml or config/**/*.yaml. When a glob pattern is used, matching files are sorted alphabetically and merged in order.

§Example
let mut options = ConfigOptions::default();
options.allow_http = true;
options.http_proxy = Some("http://proxy:8080".into());
let config = Config::load_with_options("config.yaml", options)?;
Source

pub fn required(path: impl AsRef<Path>) -> Result<Self>

Alias for load() - load a required config file

Provided for symmetry with Config::optional().

Source

pub fn required_with_options( path: impl AsRef<Path>, options: ConfigOptions, ) -> Result<Self>

Load a required config file with custom options

Source

pub fn optional(path: impl AsRef<Path>) -> Result<Self>

Load an optional configuration file

Returns an empty Config if the file doesn’t exist. Use this for configuration files that may or may not be present, such as local overrides.

Supports glob patterns like config/*.yaml or config/**/*.yaml. When a glob pattern is used, matching files are sorted alphabetically and merged in order. Returns empty config if no files match.

§Example
let base = Config::load("base.yaml")?;
let local = Config::optional("local.yaml")?;
let overrides = Config::optional("config/*.yaml")?;
base.merge(&local);
Source

pub fn merge(&mut self, other: Config)

Merge another config into this one

The other config’s values override this config’s values per ADR-004 merge semantics. File roots from both configs are unioned for path traversal protection.

Source

pub fn from_json(json: &str) -> Result<Self>

Load configuration from a JSON string

Source

pub fn set_schema(&mut self, schema: Schema)

Set or replace the schema for default value lookup

When a schema is attached, get() will return schema defaults for missing paths instead of raising PathNotFoundError.

Note: Setting a schema clears the value cache since defaults may now affect lookups.

Source

pub fn get_schema(&self) -> Option<&Schema>

Get a reference to the attached schema, if any

Source

pub fn get_raw(&self, path: &str) -> Result<&Value>

Get the raw (unresolved) value at a path

Source

pub fn get(&self, path: &str) -> Result<Value>

Get a resolved value at a path

This resolves any interpolation expressions in the value. Resolved values are cached for subsequent accesses.

If a schema is attached and the path is not found (or is null when null is not allowed), the schema default is returned instead.

Source

pub fn get_string(&self, path: &str) -> Result<String>

Get a resolved string value, with type coercion if needed

Source

pub fn get_i64(&self, path: &str) -> Result<i64>

Get a resolved integer value, with type coercion if needed

Source

pub fn get_f64(&self, path: &str) -> Result<f64>

Get a resolved float value, with type coercion if needed

Source

pub fn get_bool(&self, path: &str) -> Result<bool>

Get a resolved boolean value, with strict coercion per ADR-012

Source

pub fn resolve_all(&self) -> Result<()>

Resolve all values in the configuration eagerly

Source

pub fn to_value(&self, resolve: bool, redact: bool) -> Result<Value>

Export the configuration as a Value

§Arguments
  • resolve - If true, resolve interpolations (${…}). If false, show placeholders.
  • redact - If true, replace sensitive values with “[REDACTED]”. Only applies when resolve=true.
§Examples
// Show raw config with placeholders (safest, fastest)
let raw = config.to_value(false, false)?;

// Resolved with secrets redacted (safe for logs)
let safe = config.to_value(true, true)?;

// Resolved with secrets visible (use with caution)
let full = config.to_value(true, false)?;
Source

pub fn to_yaml(&self, resolve: bool, redact: bool) -> Result<String>

Export the configuration as YAML

§Arguments
  • resolve - If true, resolve interpolations (${…}). If false, show placeholders.
  • redact - If true, replace sensitive values with “[REDACTED]”. Only applies when resolve=true.
§Examples
// Show raw config with placeholders
let yaml = config.to_yaml(false, false)?;

// Resolved with secrets redacted
let yaml = config.to_yaml(true, true)?;
Source

pub fn to_json(&self, resolve: bool, redact: bool) -> Result<String>

Export the configuration as JSON

§Arguments
  • resolve - If true, resolve interpolations (${…}). If false, show placeholders.
  • redact - If true, replace sensitive values with “[REDACTED]”. Only applies when resolve=true.
§Examples
// Show raw config with placeholders
let json = config.to_json(false, false)?;

// Resolved with secrets redacted
let json = config.to_json(true, true)?;
Source

pub fn clear_cache(&self)

Clear the resolution cache

Source

pub fn get_source(&self, path: &str) -> Option<&str>

Get the source file for a config path

Returns the filename of the config file that provided this value. For merged configs, this returns the file that “won” for this path.

Source

pub fn dump_sources(&self) -> &HashMap<String, String>

Get all source mappings

Returns a map of config paths to their source filenames. Useful for debugging which file each value came from.

Source

pub fn register_resolver(&mut self, resolver: Arc<dyn Resolver>)

Register a custom resolver

Source

pub fn validate_raw(&self, schema: Option<&Schema>) -> Result<()>

Validate the raw (unresolved) configuration against a schema

This performs structural validation (Phase 1 per ADR-007):

  • Required keys are present
  • Object/array structure matches
  • Interpolations (${…}) are allowed as placeholders

If schema is None, uses the attached schema (set via set_schema()). Returns an error if no schema is provided and none is attached.

Source

pub fn validate(&self, schema: Option<&Schema>) -> Result<()>

Validate the resolved configuration against a schema

This performs type/value validation (Phase 2 per ADR-007):

  • Resolved values match expected types
  • Constraints (min, max, pattern, enum) are checked

If schema is None, uses the attached schema (set via set_schema()). Returns an error if no schema is provided and none is attached.

Source

pub fn validate_collect(&self, schema: Option<&Schema>) -> Vec<ValidationError>

Validate and collect all errors (instead of failing on first)

If schema is None, uses the attached schema (set via set_schema()). Returns a single error if no schema is provided and none is attached.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

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

Auto Trait Implementations§

§

impl Freeze for Config

§

impl !RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl !UnwindSafe for Config

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more