hydroperfox-lateformat

Crates.iohydroperfox-lateformat
lib.rshydroperfox-lateformat
version1.0.0
sourcesrc
created_at2024-07-23 06:36:53.669503
updated_at2024-07-23 06:36:53.669503
descriptionLate formatting of string parameters
homepage
repositoryhttps://github.com/hydroperfox/rustlateformat
max_upload_size
id1312466
size17,141
Matheus Dias de Souza (hydroperfox)

documentation

README

Late format

This crate provides a simple way of formatting parameters in a runtime string, with runtime parameter names.

This is an alternative to using complex template engines.

Example

use hydroperfox_lateformat::LateFormat;
use maplit::hashmap;

let user_string: String = "some user string: {id}".into();
assert_eq!(
    "some user string: x",
    user_string.hydroperfox_lateformat(hashmap!{"id".into() => "x".into()})
);

let user_string: String = r#"some user string: {"id"}"#.into();
assert_eq!(
    "some user string: id",
    user_string.hydroperfox_lateformat(hashmap!{"id".into() => "x".into()})
);

let user_string: String = r#"some user string: {  "id"  }"#.into();
assert_eq!(
    "some user string: id",
    user_string.hydroperfox_lateformat(hashmap!{"id".into() => "x".into()})
);

let user_string: String = "some user string: {id}".into();
assert_eq!(
    "some user string: None",
    user_string.hydroperfox_lateformat(hashmap!{})
);
Commit count: 0

cargo fmt