Struct cor_args::CfgFileHandler
source · 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
impl CfgFileHandler
sourcepub fn new<P>(file_path: P) -> Self
pub fn new<P>(file_path: P) -> Self
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");pub fn next(self, handler: Box<dyn Handler>) -> Self
Trait Implementations§
source§impl Handler for CfgFileHandler
impl Handler for CfgFileHandler
source§fn handle_request(&self, key: &str) -> Option<String>
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.
Auto Trait Implementations§
impl !RefUnwindSafe for CfgFileHandler
impl !Send for CfgFileHandler
impl !Sync for CfgFileHandler
impl Unpin for CfgFileHandler
impl !UnwindSafe for CfgFileHandler
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