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 formatvars
- AHashMap
holding the variables to use
Exceptions
- FmtError::Invalid - The format string is structured incorrectly
- FmtError::KeyError -
vars
contains an invalid key - FmtError::TypeError - the given format code for a section contains an unexpected option
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());