EnvSource

Trait EnvSource 

Source
pub trait EnvSource {
    // Required method
    fn get(&self, key: &str) -> Option<String>;
}
Expand description

环境变量查找源 trait。用于支持多种来源的变量查找。 Trait for abstracting environment variable lookup source.

§用法示例

use rush_var::expand_env;
let env = [ ("FOO", "bar") ];
let res = expand_env("$FOO", &env);
assert_eq!(res, "bar");

Required Methods§

Source

fn get(&self, key: &str) -> Option<String>

获取指定 key 的变量值,如果不存在则返回 None。

Implementations on Foreign Types§

Source§

impl EnvSource for BTreeMap<String, String>

BTreeMap 作为环境变量源

Source§

fn get(&self, key: &str) -> Option<String>

Source§

impl EnvSource for HashMap<String, String>

HashMap 作为环境变量源

Source§

fn get(&self, key: &str) -> Option<String>

Source§

impl EnvSource for Vars

系统环境变量(字符串)

Source§

fn get(&self, key: &str) -> Option<String>

Source§

impl EnvSource for VarsOs

系统环境变量(OsString)

Source§

fn get(&self, key: &str) -> Option<String>

Source§

impl<'a> EnvSource for &'a [(&'a str, &'a str)]

切片 &[(&str, &str)] 作为环境变量源,适用于快速mock和常量环境。

Source§

fn get(&self, key: &str) -> Option<String>

Source§

impl<T: EnvSource + ?Sized> EnvSource for &T

为任意已实现 EnvSource 的类型的引用自动实现 EnvSource

Source§

fn get(&self, key: &str) -> Option<String>

Implementors§

Source§

impl<A: EnvSource, B: EnvSource> EnvSource for EnvSourceChain<A, B>

Source§

impl<F> EnvSource for FnEnvSource<F>
where for<'a> F: Fn(&'a str) -> Option<String>,