Trait ParseEnv

Source
pub trait ParseEnv: Sized {
    type Err: Display;

    // Required method
    fn parse_env(value: String) -> Result<Self, Self::Err>;
}
Expand description

Define the parsing function for a type from a String environment variable.

Check the source for the builtin type definitions for this trait if you’re concerned about the parsing logic.

Required Associated Types§

Source

type Err: Display

The std::fmt::Display of this error message will appear in the panic message when parsing fails.

Required Methods§

Source

fn parse_env(value: String) -> Result<Self, Self::Err>

Tries to parse the value from std::env::var.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ParseEnv for &'static str

Source§

type Err = Infallible

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for IpAddr

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for SocketAddr

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for bool

bool allows two common conventions:

  • String either “true” or “false” (case insensitive)
  • Integer either 0 or 1

Anything else will result in a ParseError.

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for f32

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for f64

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for i8

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for i16

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for i32

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for i64

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for i128

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for isize

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for u8

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for u16

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for u32

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for u64

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for u128

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for usize

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for String

Source§

type Err = Infallible

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for Ipv4Addr

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for Ipv6Addr

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for Duration

Duration by default is parsed as f64 seconds;

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl ParseEnv for PathBuf

Source§

type Err = ParseError

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl<T> ParseEnv for Option<T>
where T: ParseEnv,

Source§

type Err = <T as ParseEnv>::Err

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Source§

impl<T> ParseEnv for Vec<T>
where T: ParseEnv,

Vec<T> is by default parsed as comma-separated values.

Source§

type Err = <T as ParseEnv>::Err

Source§

fn parse_env(value: String) -> Result<Self, Self::Err>

Implementors§