5 unstable releases

0.2.1 Nov 29, 2022
0.2.0 Apr 2, 2020
0.1.1 Jun 4, 2019
0.1.0 May 28, 2019
0.0.1 May 14, 2019

#167 in Template engine

Download history 633/week @ 2024-03-03 608/week @ 2024-03-10 514/week @ 2024-03-17 481/week @ 2024-03-24 799/week @ 2024-03-31 564/week @ 2024-04-07 745/week @ 2024-04-14 667/week @ 2024-04-21 601/week @ 2024-04-28 439/week @ 2024-05-05 583/week @ 2024-05-12 579/week @ 2024-05-19 375/week @ 2024-05-26 536/week @ 2024-06-02 525/week @ 2024-06-09 511/week @ 2024-06-16

1,962 downloads per month
Used in 6 crates

MIT/Apache

8KB
106 lines

envsubst

crates.io Documentation

A simple Rust library for variables substitution.

This library provide helper functions for string manipulation, taking values from a context environment map and substituting all matching placeholders.

Its name and logic is similar to the envsubst GNU utility, but this only supports braces-delimited variables (i.e. ${foo}) and takes replacement values from an explicit map of variables.

License

Licensed under either of

at your option.


lib.rs:

Variables substitution in string templates.

This library provide helper functions for string manipulation, taking values from a context environment map and substituting all matching placeholders.

Its name and logic is similar to the envsubst GNU utility, but this only supports braces-delimited variables (i.e. ${foo}) and takes replacement values from an explicit map of variables.

Example

let base_url = "${protocol}://${hostname}/${endpoint}";
assert!(envsubst::is_templated(base_url));

let mut context = std::collections::HashMap::new();
context.insert("protocol".to_string(), "https".to_string());
context.insert("hostname".to_string(), "example.com".to_string());
context.insert("endpoint".to_string(), "login".to_string());
assert!(envsubst::validate_vars(&context).is_ok());

let final_url = envsubst::substitute(base_url, &context).unwrap();
assert!(!envsubst::is_templated(&final_url));
assert_eq!(final_url, "https://example.com/login");

Dependencies

~305–770KB
~18K SLoC