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:
- The
'%'
character, which marks the start of the specifier.
- Mapping key (optional), consisting of a parenthesised sequence of characters (for example,
(somename)
).
- Conversion flags (optional), which affect the result of some conversion types.
- 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.
- 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.
- Length modifier (optional).
- 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.
use dynfmt::{Format, PythonFormat};
let formatted = PythonFormat.format("hello, %s", &["world"]);
assert_eq!("hello, world", formatted.expect("formatting failed"));
The iterator returned by [iter_args
]. Read more
Returns an iterator over format arguments in the format string. Read more
Formats the given string with the specified arguments. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static