Function shuttle_runtime::strfmt
source · pub fn strfmt<K, T, 'a>(
fmtstr: &str,
vars: &HashMap<K, T>
) -> Result<String, FmtError>where
T: DisplayStr,
K: Hash + Eq + FromStr,Expand description
Rust-style format a string given a HashMap of the variables.
Arguments
fmtstr- A string defining the formatvars- AHashMapholding the variables to use
Exceptions
- FmtError::Invalid - The format string is structured incorrectly
- FmtError::KeyError -
varscontains 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());