[−][src]Struct dynfmt::python::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:
- 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.
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]
Auto Trait Implementations
impl RefUnwindSafe for PythonFormat
impl Send for PythonFormat
impl Sync for PythonFormat
impl Unpin for PythonFormat
impl UnwindSafe for PythonFormat
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,