Crates.io | late_substitution |
lib.rs | late_substitution |
version | 1.0.1 |
source | src |
created_at | 2023-10-23 11:32:31.662167 |
updated_at | 2023-10-23 11:37:25.928705 |
description | Late substitution of string parameters |
homepage | |
repository | https://github.com/hydroper/rust_late_substitution |
max_upload_size | |
id | 1011236 |
size | 5,457 |
This crate provides a simple way of substituting parameters in an arbitrary string, where parameter names are arbitrary.
This is an alternative to using complex template engines.
use late_substitution::LateSubstitution;
use maplit::hashmap;
let user_string: String = "some user string: {id}".into();
assert_eq!(
"some user string: x",
user_string.late_substitution(hashmap!{"id".into() => "x".into()})
);
let user_string: String = r#"some user string: {"id"}"#.into();
assert_eq!(
"some user string: id",
user_string.late_substitution(hashmap!{"id".into() => "x".into()})
);
let user_string: String = r#"some user string: { "id" }"#.into();
assert_eq!(
"some user string: id",
user_string.late_substitution(hashmap!{"id".into() => "x".into()})
);
let user_string: String = "some user string: {id}".into();
assert_eq!(
"some user string: None",
user_string.late_substitution(hashmap!{})
);