pub enum EnvType {
Dev,
Test,
Stg,
Prod,
Custom(&'static str),
}Expand description
EnvType is an enum that represents the environment type. EnvType is derived from the strum crate, which provides the ability to convert the string to the enum.
§Example
use env_type::types::EnvType;
use std::str::FromStr;
let env = EnvType::from_str("d").unwrap();
assert_eq!(EnvType::Dev, env);
let custom_env = EnvType::Custom("Custom");
assert_eq!(EnvType::Custom("Custom"), custom_env);Variants§
Implementations§
Source§impl EnvType
impl EnvType
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
EnvType::from_env is a function that returns the environment type from the environment variable. This is deligated to from_env_key with EnvType as default from env key. The default environment type is Dev.
§Example
use env_type::types::EnvType;
use std::str::FromStr;
std::env::set_var("ENV", "Production");
let env = EnvType::from_env();
assert_eq!(EnvType::Prod, env);Sourcepub fn from_env_key<K: EnvKey>() -> Self
pub fn from_env_key<K: EnvKey>() -> Self
EnvType::from_env_key is a function that returns the environment type from the environment variable. The default environment type is Dev.
§Example
use env_type::types::EnvType;
use std::str::FromStr;
std::env::set_var("ENV", "Test");
let env = EnvType::from_env_key::<EnvType>();
assert_eq!(EnvType::Test, env);Sourcepub fn from_env_types<S: AsEnvStr, K: EnvKey>(s: S) -> Self
pub fn from_env_types<S: AsEnvStr, K: EnvKey>(s: S) -> Self
EnvType::from_env_types is a function that returns the EnvType from AsEnvStr and EnvKey.
Sourcepub fn from_env_str<T: AsEnvTypeStr>(t: T) -> Self
pub fn from_env_str<T: AsEnvTypeStr>(t: T) -> Self
EnvType::from_env_str is a function that returns the environment type from the string. The default environment type is Dev.
§Example
use env_type::types::{EnvType, AsEnvTypeStr};
use std::str::FromStr;
struct Config {
env_str: String,
}
let config = Config {
env_str: "Production".to_string(),
};
impl AsEnvTypeStr for Config {
fn as_env_type_str(&self) -> Option<String> {
Some(self.env_str.clone())
}
}
let env = EnvType::from_env_str(config);
assert_eq!(EnvType::Prod, env);Trait Implementations§
Source§impl AsEnvStr for EnvType
EnvType is an implementation of the AsEnvStr trait.
EnvType is based on env var.
impl AsEnvStr for EnvType
EnvType is an implementation of the AsEnvStr trait. EnvType is based on env var.
fn as_env_str<T: EnvKey>(&self) -> String
Source§impl EnvKey for EnvType
EnvType is an implementation of the EnvKey trait.
The default environment key is “ENV”.
impl EnvKey for EnvType
EnvType is an implementation of the EnvKey trait. The default environment key is “ENV”.