Trait strfmt::Format

source ·
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§

source

fn format<K, D: DisplayStr>(&self, vars: &HashMap<K, D>) -> Result<String>where K: Hash + Eq + FromStr,

format a string using strfmt

Arguments
  • vars - A HashMap 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());
source

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

Implementations on Foreign Types§

source§

impl Format for str

source§

fn format<K, D: DisplayStr>(&self, vars: &HashMap<K, D>) -> Result<String>where K: Hash + Eq + FromStr,

source§

fn format_display<'a, 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
source§

impl Format for String

source§

fn format<'a, K, D: DisplayStr>(&self, vars: &HashMap<K, D>) -> Result<String>where K: Hash + Eq + FromStr,

source§

fn format_display<'a, 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

Implementors§