[][src]Struct dynfmt::python::PythonFormat

pub struct PythonFormat;

Format implementation for old-style Python formatting.

Python uses a syntax similar to sprintf in the C language. Each format argument contains two or more characters and has the following components, which must occur in this order:

  1. The '%' character, which marks the start of the specifier.
  2. Mapping key (optional), consisting of a parenthesised sequence of characters (for example, (somename)).
  3. Conversion flags (optional), which affect the result of some conversion types.
  4. Minimum field width (optional). If specified as an '*' (asterisk), the actual width is read from the next element of the tuple in values, and the object to convert comes after the minimum field width and optional precision.
  5. Precision (optional), given as a '.' (dot) followed by the precision. If specified as '*' (an asterisk), the actual width is read from the next element of the tuple in values, and the value to convert comes after the precision.
  6. Length modifier (optional).
  7. Conversion type.

Most of the conversion types are mapped to the standard Display trait. The %r conversion type is implemented as JSON, if the json feature is active and will otherwise error.

For the full specification, please refer to the Python string formatting docs.

Example

use dynfmt::{Format, PythonFormat};

let formatted = PythonFormat.format("hello, %s", &["world"]);
assert_eq!("hello, world", formatted.expect("formatting failed"));

Trait Implementations

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

type Iter = PythonIter<'f>

The iterator returned by [iter_args]. Read more

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

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]