pub struct EnvParser;Expand description
A parser for environment variables.
Trait Implementations§
Source§impl<T: AsRef<str>> Parser<T> for EnvParser
impl<T: AsRef<str>> Parser<T> for EnvParser
Source§fn parse(args: T) -> Result<Self::Item, Self::Error>
fn parse(args: T) -> Result<Self::Item, Self::Error>
Parses environment variables based on a given prefix.
This function filters environment variables that start with the given
prefix, removes the prefix from the key, converts the key to
lowercase, and stores the resulting key-value pairs in a Value.
§Arguments
args- A string-like type that represents the prefix to filter environment variables.
§Returns
Result<Self::Item, Self::Error>- AResultcontaining either:Ok(Value::Table(map))wheremapis aMapof filtered and processed environment variables.Err(Error)if an error occurs during parsing (note: this implementation always returnsOk).
§Examples
use std::env;
use realme::prelude::*;
// Assuming environment variables: APP_NAME=MyApp, APP_VERSION=1.0
env::set_var("APP_NAME", "MyApp");
env::set_var("APP_VERSION", "1.0");
let result = EnvParser::parse("APP_");
assert!(result.is_ok());
// The resulting map would contain: {"name": "MyApp", "version": "1.0"}Auto Trait Implementations§
impl Freeze for EnvParser
impl RefUnwindSafe for EnvParser
impl Send for EnvParser
impl Sync for EnvParser
impl Unpin for EnvParser
impl UnwindSafe for EnvParser
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