Struct Extension

Source
pub struct Extension {
    flag: Option<Flag>,
    width: Option<u8>,
    colons: u8,
}
Expand description

These are “extensions” to the standard strftime conversion specifiers.

This type represents which flags and/or padding were provided with a specifier. For example, %_3d uses 3 spaces of padding.

Currently, this type provides no structured introspection facilities. It is exported and available only via implementations of the Custom trait for reasons of semver compatible API evolution. If you have use cases for introspecting this type, please open an issue.

Fields§

§flag: Option<Flag>§width: Option<u8>§colons: u8

Implementations§

Source§

impl Extension

Source

fn write_str<W: Write>( &self, default: Case, string: &str, wtr: &mut W, ) -> Result<(), Error>

Writes the given string using the default case rule provided, unless an option in this extension config overrides the default case.

Source

fn write_str_cold<W: Write>( &self, default: Case, string: &str, wtr: &mut W, ) -> Result<(), Error>

Source

fn write_int<W: Write>( &self, pad_byte: u8, pad_width: Option<u8>, number: impl Into<i64>, wtr: &mut W, ) -> Result<(), Error>

Writes the given integer using the given padding width and byte, unless an option in this extension config overrides a default setting.

Source

fn write_fractional_seconds<W: Write>( &self, number: impl Into<i64>, wtr: &mut W, ) -> Result<(), Error>

Writes the given number of nanoseconds as a fractional component of a second. This does not include the leading ..

The width setting on Extension is treated as a precision setting.

Source§

impl Extension

Source

fn parse_number<'i>( &self, default_pad_width: usize, default_flag: Flag, inp: &'i [u8], ) -> Result<(i64, &'i [u8]), Error>

Parse an integer with the given default padding and flag settings.

The default padding is usually 2 (4 for %Y) and the default flag is usually Flag::PadZero (there are no cases where the default flag is different at time of writing). But both the padding and the flag can be overridden by the settings on this extension.

Generally speaking, parsing ignores everything in an extension except for padding. When padding is set, then parsing will limit itself to a number of digits equal to the greater of the default padding size or the configured padding size. This permits %Y%m%d to parse 20240730 successfully, for example.

The remaining input is returned. This returns an error if the given input is empty.

Source§

impl Extension

Source

fn parse_flag<'i>(fmt: &'i [u8]) -> Result<(Option<Flag>, &'i [u8]), Error>

Parses an optional directive flag from the beginning of fmt. This assumes fmt is not empty and guarantees that the return unconsumed slice is also non-empty.

Source

fn parse_width<'i>(fmt: &'i [u8]) -> Result<(Option<u8>, &'i [u8]), Error>

Parses an optional width that comes after a (possibly absent) flag and before the specifier directive itself. And if a width is parsed, the slice returned does not contain it. (If that slice is empty, then an error is returned.)

Note that this is also used to parse precision settings for %f and %.f. In the former case, the width is just re-interpreted as a precision setting. In the latter case, something like %5.9f is technically valid, but the 5 is ignored.

Source

fn parse_colons<'i>(fmt: &'i [u8]) -> (u8, &'i [u8])

Parses an optional number of colons.

This is meant to be used immediately before the conversion specifier (after the flag and width has been parsed).

This supports parsing up to 3 colons. The colons are used in some cases for alternate specifiers. e.g., %:Q or %:::z.

Trait Implementations§

Source§

impl Clone for Extension

Source§

fn clone(&self) -> Extension

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Extension

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.