pub trait Format {
// Required methods
fn format<K, D: DisplayStr>(&self, vars: &HashMap<K, D>) -> Result<String>
where K: Hash + Eq + FromStr;
fn format_display<K, D: Display>(
&self,
vars: &HashMap<K, D>
) -> Result<String>
where K: Hash + Eq + FromStr;
}
Expand description
This trait is a shortcut for [strfmt] for an example see Format::format
Required Methods§
sourcefn format<K, D: DisplayStr>(&self, vars: &HashMap<K, D>) -> Result<String>where
K: Hash + Eq + FromStr,
fn format<K, D: DisplayStr>(&self, vars: &HashMap<K, D>) -> Result<String>where K: Hash + Eq + FromStr,
format a string using strfmt
Arguments
vars
- AHashMap
holding the variables to use
Errors
Errors are passed directly from strfmt, for details see [strfmt]
Examples
use std::collections::HashMap;
use std::f64::consts::PI;
use strfmt::Format;
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!("{}", "|{Alpha}|{Beta:<5.2}|".format(&my_vars).unwrap());
sourcefn format_display<K, D: Display>(&self, vars: &HashMap<K, D>) -> Result<String>where
K: Hash + Eq + FromStr,
fn format_display<K, D: Display>(&self, vars: &HashMap<K, D>) -> Result<String>where K: Hash + Eq + FromStr,
👎Deprecated since 0.2.0: This function contains a bug when formatting numbers. Use format instead
format a string using strfmt_display see Format::format for usage