[][src]Crate far

Find And Replace string template engine

Provided with a template and a map, Find And Replace will attempt to find all the keys (delimited with ${}) in the template and replace them with the corresponding value in the map. For example:

let template = "${capitalized specific} are my favorite ${category}.";

let mut args = HashMap::new();

args.insert("capitalized specific", "Cats");
args.insert("category", "animal");

let s = far(&template, &args)?;

assert_eq!(s, "Cats are my favorite animal.");

If it fails for some reason, an explanation of why will be returned:

let template = "${capitalized specific} are my favorite ${category}.";

let mut args = HashMap::new();

args.insert("capitalized specific", "Cats");
// Note the typo here
args.insert("catglory", "animal");

match far(&template, &args) {
    Ok(_) => panic!(),
    Err(e) => {
        assert_eq!(
            format!("{}", e),
            r#"missing key: "category"; extraneous key: "catglory""#
        );
    }
}

Additional examples and weird edge-case behaviors can be found in src/tests.

Structs

Errors

Errors that occured while finding and replacing

Enums

Error

A single specific error

Functions

far

Find And Replace