EnvParser

Struct EnvParser 

Source
pub struct EnvParser;
Expand description

A parser for environment variables.

Trait Implementations§

Source§

impl Debug for EnvParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: AsRef<str>> Parser<T> for EnvParser

Source§

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> - A Result containing either:
    • Ok(Value::Table(map)) where map is a Map of filtered and processed environment variables.
    • Err(Error) if an error occurs during parsing (note: this implementation always returns Ok).
§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"}
Source§

type Item = Value

The type of item produced by the parser. Read more
Source§

type Error = Error

The type of error that can occur during parsing. 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> 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>,

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.