pub trait FromEnvValue: Sized {
// Required method
fn from_env_value(s: String) -> Result<Self, String>;
}Expand description
Trait for converting a raw env-var string into a typed value.
Implementations are provided for all FromStr types via a blanket impl.
You can implement this trait for custom types that need special parsing.
§Example
use dotenv::FromEnvValue;
let n = <u16 as FromEnvValue>::from_env_value("42".into()).unwrap();
assert_eq!(n, 42);
let b = <bool as FromEnvValue>::from_env_value("true".into()).unwrap();
assert!(b);
let err = <u16 as FromEnvValue>::from_env_value("abc".into()).unwrap_err();
assert!(!err.is_empty());Required Methods§
Sourcefn from_env_value(s: String) -> Result<Self, String>
fn from_env_value(s: String) -> Result<Self, String>
Convert the raw string value into Self.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".