#string #formatting #batch #windows #environment

expand_str

ExpandEnvironmentStrings-like function and string formatting utility

2 releases

0.1.1 Jun 18, 2020
0.1.0 Oct 15, 2019

#2 in #string-formatting

Download history 12/week @ 2022-06-11 101/week @ 2022-06-18 98/week @ 2022-06-25 73/week @ 2022-07-02 185/week @ 2022-07-09 110/week @ 2022-07-16 56/week @ 2022-07-23 60/week @ 2022-07-30 75/week @ 2022-08-06 7/week @ 2022-08-13 50/week @ 2022-08-20 78/week @ 2022-08-27 204/week @ 2022-09-03 141/week @ 2022-09-10 101/week @ 2022-09-17 206/week @ 2022-09-24

673 downloads per month

WTFPL license

10KB
206 lines

expand_str

ExpandEnvironmentStrings emulation with more strict input checking and a way to substitute your own variable values.

Example

Add expand_str to your dependencies of your Cargo.toml:

[dependencies]
expand_str = "0.1"

And then, in your rust file:


fn main() {
    println!("{}", expand_str::expand_string_with_env("This is what's in your PATH: %PATH%").unwrap());
}

If you only want string formatting, environment variable access code can be dropped, e.g.:

[dependencies.expand_str]
version = "0.1"
default-features = false

(Exact feature name is env, but there are no other features at the moment).

Formatting-only example:

fn main() {
    let values = {
        let mut values = HashMap::new();
        values.insert("DRINK", "cup of tea");
        values.insert("FOOD", "cookies");
        values
    };

    let src = "Here is a %DRINK% and some %FOOD%.";
    let x = expand_string_with_values(src, |id| values.get(id)).unwrap();
    println!("{}", x);
}

No runtime deps

Features

  • env