Struct mimi::Formatter

source ·
pub struct Formatter { /* private fields */ }
Expand description

A Formatter takes a bunch of key/value pairs and interpolates them into a mimi format string.

Implementations§

The names of all the variables in the format string.

Examples
let formatter: mimi::Formatter = "$foo $foo ${bar}baz".parse().unwrap();
let expected: HashSet<String> = hashset!["foo".into(), "bar".into()];
assert_eq!(formatter.keys(), &expected);

Formats the given values using ANSI terminal codes.

Yields the text of each leaf node under root with variables substituted by looking up in values and using base as the base of each style. Combined with a function that can take a String and a Style and format them, this gives you the ability to work with arbitrary output formats.

Returns an iterator over (text, style) pairs. We do not guarantee that the representation is minimal (in that it’s possible for there to be adjacent pairs with identical styles).

Examples
use std::collections::HashMap;
let formatter: mimi::Formatter = "lit %[red]{fmt} $var".parse().unwrap();
let mut values = HashMap::new();
values.insert("var", "value".to_owned());
let spans: Vec<_> = formatter.spans(&values).collect();
let red = mimi::Style { foreground: Some(mimi::Color::Red), ..mimi::Style::default() };

assert_eq!(spans, vec![
  ("lit ".into(), mimi::Style::default()),
  ("fmt".into(), red),
  // Note that the next two might get merge in some future version.
  (" ".into(), mimi::Style::default()),
  ("value".into(), mimi::Style::default()),
]);

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.