Trait dynfmt::Format[][src]

pub trait Format<'f> {
    type Iter: Iterator<Item = ArgumentResult<'f>>;
    fn iter_args(&self, format: &'f str) -> Result<Self::Iter, Error<'f>>;

    fn format<A>(
        &self,
        format: &'f str,
        arguments: A
    ) -> Result<Cow<'f, str>, Error<'f>>
    where
        A: FormatArgs
, { ... } }

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>>[src]

The iterator returned by iter_args.

Loading content...

Required methods

fn iter_args(&self, format: &'f str) -> Result<Self::Iter, Error<'f>>[src]

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.

Loading content...

Provided methods

fn format<A>(
    &self,
    format: &'f str,
    arguments: A
) -> Result<Cow<'f, str>, Error<'f>> where
    A: FormatArgs
[src]

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"));
Loading content...

Implementors

impl<'f> Format<'f> for SimpleCurlyFormat[src]

type Iter = SimpleCurlyIter<'f>

impl<'f> Format<'f> for PythonFormat[src]

type Iter = PythonIter<'f>

impl<'f> Format<'f> for NoopFormat[src]

type Iter = Empty<ArgumentResult<'f>>

Loading content...