expand_str

Crates.ioexpand_str
lib.rsexpand_str
version0.1.1
sourcesrc
created_at2019-10-15 07:07:41.505488
updated_at2020-06-18 09:57:58.093637
descriptionExpandEnvironmentStrings-like function and string formatting utility
homepage
repositoryhttps://github.com/TechPriest/expand_str.git
max_upload_size
id172617
size10,108
TechPriest (TechPriest)

documentation

README

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);
}
Commit count: 40

cargo fmt