pub struct ParsedFmt<'a> { /* private fields */ }
Expand description

Preparsed formatting terms.

This is faster if you will be using the same format string again and again with different inputs.

use runtime_format::{FormatArgs, FormatKey, FormatKeyError, ParsedFmt};
use core::fmt;
impl FormatKey for DateTime {
    fn fmt(&self, key: &str, f: &mut fmt::Formatter<'_>) -> Result<(), FormatKeyError> {
         // ...
    }
}

let now = DateTime::now();
let fmt = ParsedFmt::new("{month} {day} {year} {hours}:{minutes}:{seconds}").unwrap();
let args = FormatArgs::new(&fmt, &now);
let expected = "Jan 25 2023 16:27:53";
assert_eq!(args.to_string(), expected);

Implementations§

Parse the given format string.

Errors

If the string could not be parsed, or there is a key that is unacceptable.

Return the keys that will be used when formatting.

let fmt = "Hello, {recipient}. Hope you are having a nice {time_descriptor}.";
let parsed = ParsedFmt::new(fmt).unwrap();
let keys: Vec<_> = parsed.keys().collect();
assert_eq!(keys, ["recipient", "time_descriptor"]);

Combine this parsed format with the given values into a FormatArgs

Trait Implementations§

Formats the value using the given formatter. Read more
The Parser type that returns the ParseSegments
Turn this value into the parser
Get the unparsed str from this parser. Used to determine if there was an error while parsing.
The type returned in the event of a conversion error.
Performs the conversion.

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 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.