YamlFileAdapter

Struct YamlFileAdapter 

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

Configuration source adapter for YAML files.

This adapter reads configuration values from YAML files. It supports automatic discovery of configuration files in OS-appropriate locations, as well as custom file paths.

§Priority

YAML files have a priority of 1, which means they are overridden by both environment variables (priority 2) and command-line arguments (priority 3).

§Examples

use hexcfg::adapters::YamlFileAdapter;
use hexcfg::ports::ConfigSource;

// Load from a specific file
let adapter = YamlFileAdapter::from_file("/path/to/config.yaml").unwrap();

// Load from default OS location
let adapter = YamlFileAdapter::from_default_location("myapp", "com.example").unwrap();

Implementations§

Source§

impl YamlFileAdapter

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>

Creates a new YAML file adapter from a specific file path.

§Arguments
  • path - Path to the YAML file
§Examples
use hexcfg::adapters::YamlFileAdapter;

let adapter = YamlFileAdapter::from_file("/etc/myapp/config.yaml").unwrap();
Source

pub fn from_default_location(app_name: &str, qualifier: &str) -> Result<Self>

Creates a new YAML file adapter from the default OS-appropriate location.

This method uses the directories crate to determine the appropriate configuration directory for the current operating system.

§Arguments
  • app_name - The application name (e.g., “myapp”)
  • qualifier - The organization/qualifier (e.g., “com.example”)
§Examples
use hexcfg::adapters::YamlFileAdapter;

let adapter = YamlFileAdapter::from_default_location("myapp", "com.example").unwrap();
Source

pub fn with_filename( app_name: &str, qualifier: &str, filename: &str, ) -> Result<Self>

Creates a new YAML file adapter with a custom file name in the default location.

§Arguments
  • app_name - The application name
  • qualifier - The organization/qualifier
  • filename - The configuration file name (e.g., “settings.yaml”)
§Examples
use hexcfg::adapters::YamlFileAdapter;

let adapter = YamlFileAdapter::with_filename("myapp", "com.example", "settings.yaml").unwrap();
Source

pub fn file_path(&self) -> &Path

Returns the path to the configuration file.

Trait Implementations§

Source§

impl Clone for YamlFileAdapter

Source§

fn clone(&self) -> YamlFileAdapter

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 ConfigSource for YamlFileAdapter

Source§

fn name(&self) -> &str

Returns the name of this configuration source. Read more
Source§

fn priority(&self) -> u8

Returns the priority of this configuration source. Read more
Source§

fn get(&self, key: &ConfigKey) -> Result<Option<ConfigValue>>

Retrieves a configuration value for the given key. Read more
Source§

fn all_keys(&self) -> Result<Vec<ConfigKey>>

Returns all configuration keys available in this source. Read more
Source§

fn reload(&mut self) -> Result<()>

Reloads the configuration from the source. Read more
Source§

fn get_str(&self, key: &str) -> Result<Option<ConfigValue>>

Retrieves a configuration value for the given key string. Read more
Source§

impl Debug for YamlFileAdapter

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> 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> 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