Trait EnvKey

Source
pub trait EnvKey {
    // Required method
    fn key() -> &'static str;
}
Expand description

EnvKey is a trait that represents the environment key.

§Example

use env_type::types::{EnvType, EnvKey};
use std::str::FromStr;

struct NewEnvKey;

impl EnvKey for NewEnvKey {
   fn key() -> &'static str {
      "NEW_ENV"
  }
}

std::env::set_var("NEW_ENV", "Production");
let env = EnvType::from_env_key::<NewEnvKey>();
assert_eq!(EnvType::Prod, env);

Required Methods§

Source

fn key() -> &'static str

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.

Implementors§

Source§

impl EnvKey for EnvType

EnvType is an implementation of the EnvKey trait. The default environment key is “ENV”.