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

#190 in Template engine

Download history 398/week @ 2024-12-25 571/week @ 2025-01-01 788/week @ 2025-01-08 850/week @ 2025-01-15 1246/week @ 2025-01-22 787/week @ 2025-01-29 1644/week @ 2025-02-05 840/week @ 2025-02-12 1128/week @ 2025-02-19 1237/week @ 2025-02-26 816/week @ 2025-03-05 1287/week @ 2025-03-12 1120/week @ 2025-03-19 1064/week @ 2025-03-26 842/week @ 2025-04-02 760/week @ 2025-04-09

3,935 downloads per month
Used in 11 crates

MIT/Apache

8KB
106 lines

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");

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.

Dependencies

~210–650KB
~15K SLoC