[−][src]Trait dynfmt::Format
A format for string formatting.
This trait exposes formatting helper functions and lower-level utilities to interface with format strings.
In its core, a format can parse a format string and return an iterator over ArgumentSpecs
.
Each specification refers to arguments in and [argument list] and contains information on how
to format it.
Associated Types
type Iter: Iterator<Item = ArgumentResult<'f>>
The iterator returned by iter_args
.
Required methods
fn iter_args(&self, format: &'f str) -> Result<Self::Iter, Error<'f>>
Returns an iterator over format arguments in the format string.
This method is not meant to be used directly, instead use some of the provided methods to format a string.
The iterator and this method are responsible for parsing the format string correctly and
returning ArgumentSpecs
for each argument in the format string. See the module level
documentation for an example of how to implement this method.
Provided methods
fn format<A>(
&self,
format: &'f str,
arguments: A
) -> Result<Cow<'f, str>, Error<'f>> where
A: FormatArgs,
&self,
format: &'f str,
arguments: A
) -> Result<Cow<'f, str>, Error<'f>> where
A: FormatArgs,
Formats the given string with the specified arguments.
Individual arguments must implement Debug
and serde::Serialize
. The arguments
container must implement the FormatArgs
trait.
use dynfmt::{Format, NoopFormat}; let formatted = NoopFormat.format("hello, world", &["unused"]); assert_eq!("hello, world", formatted.expect("formatting failed"));