late_substitution

Crates.iolate_substitution
lib.rslate_substitution
version1.0.1
sourcesrc
created_at2023-10-23 11:32:31.662167
updated_at2023-10-23 11:37:25.928705
descriptionLate substitution of string parameters
homepage
repositoryhttps://github.com/hydroper/rust_late_substitution
max_upload_size
id1011236
size5,457
Matheus Dias de Souza (hydroper)

documentation

README

Late substitution

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.

Example

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!{})
);
Commit count: 4

cargo fmt