Function strfmt::strfmt

source ·
pub fn strfmt<'a, K, T: DisplayStr>(
    fmtstr: &str,
    vars: &HashMap<K, T>
) -> Result<String>where
    K: Hash + Eq + FromStr,
Expand description

Rust-style format a string given a HashMap of the variables.

Arguments

  • fmtstr - A string defining the format
  • vars - A HashMap holding the variables to use

Exceptions

Examples

use std::collections::HashMap;
use std::f64::consts::PI;
use strfmt::strfmt;

let mut my_vars: HashMap<String, f64> = HashMap::new();
my_vars.insert("Alpha".to_string(),42.0);
my_vars.insert("Beta".to_string(),PI);

println!("{}", strfmt("{Alpha} {Beta:<5.2}",&my_vars).unwrap());