pub struct CfgFileHandler { /* private fields */ }
Expand description

A configuration file handler for reading key-value pairs from a file.

The CfgFileHandler is used to read configuration data from a file and provide it as key-value pairs. It supports chaining multiple handlers for fallback behavior.

Examples

use cor_args::{CfgFileHandler, Handler};

// Create a new CfgFileHandler for a specific file path
let handler = CfgFileHandler::new("config.toml");

// Add a fallback handler
//let handler = handler.next(some_other_handler.into());

// Handle a configuration request
let value = handler.handle_request("some_key");

Implementations§

source§

impl CfgFileHandler

source

pub fn new<P>(file_path: P) -> Self
where P: Into<PathBuf>,

Create a new CfgFileHandler for the specified file path.

Parameters
  • file_path: A path to the configuration file.
Returns

A new CfgFileHandler instance.

Examples
use cor_args::CfgFileHandler;

let handler = CfgFileHandler::new("config.toml");
source

pub fn next(self, handler: Box<dyn Handler>) -> Self

Trait Implementations§

source§

impl Handler for CfgFileHandler

source§

fn handle_request(&self, key: &str) -> Option<String>

Handle a configuration request and return the value associated with the provided key.

This method attempts to read the configuration file and retrieve the value associated with the given key. If the key is not found, it may delegate the request to a fallback handler if one is defined.

Parameters
  • key: A string representing the configuration key to retrieve.
Returns

An Option containing the value associated with the key, or None if the key is not found.

source§

impl Into<Box<dyn Handler>> for CfgFileHandler

source§

fn into(self) -> Box<dyn Handler>

Converts this type into the (usually inferred) input type.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.