Struct Formatter

Source
pub(super) struct Formatter<'c, 'f, 't, 'w, W, L> {
    pub(super) config: &'c Config<L>,
    pub(super) fmt: &'f [u8],
    pub(super) tm: &'t BrokenDownTime,
    pub(super) wtr: &'w mut W,
}

Fields§

§config: &'c Config<L>§fmt: &'f [u8]§tm: &'t BrokenDownTime§wtr: &'w mut W

Implementations§

Source§

impl<'c, 'f, 't, 'w, W: Write, L: Custom> Formatter<'c, 'f, 't, 'w, W, L>

Source

pub(super) fn format(&mut self) -> Result<(), Error>

Source

fn format_one(&mut self) -> Result<(), Error>

Source

fn f(&self) -> u8

Returns the byte at the current position of the format string.

§Panics

This panics when the entire format string has been consumed.

Source

fn bump_fmt(&mut self) -> bool

Bumps the position of the format string.

This returns true in precisely the cases where self.f() will not panic. i.e., When the end of the format string hasn’t been reached yet.

Source

fn utf8_decode_and_bump(&mut self) -> Result<char, Error>

Decodes a Unicode scalar value from the beginning of fmt and advances the parser accordingly.

If a Unicode scalar value could not be decoded, then an error is returned.

It would be nice to just pass through bytes as-is instead of doing actual UTF-8 decoding, but since the Write trait only represents Unicode-accepting buffers, we need to actually do decoding here.

§Panics

When self.fmt is empty. i.e., Only call this when you know there is some remaining bytes to parse.

Source

fn parse_extension(&mut self) -> Result<Extension, Error>

Parses optional extensions before a specifier directive. That is, right after the %. If any extensions are parsed, the parser is bumped to the next byte. (If no next byte exists, then an error is returned.)

Source

fn parse_flag(&mut self) -> Result<Option<Flag>, Error>

Parses an optional flag. And if one is parsed, the parser is bumped to the next byte. (If no next byte exists, then an error is returned.)

Source

fn parse_width(&mut self) -> Result<Option<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 parser is bumped to the next byte. (If no next byte exists, 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(&mut self) -> u8

Parses an optional number of colons (up to 3) immediately before a conversion specifier.

Source

fn fmt_ampm_lower(&mut self, ext: &Extension) -> Result<(), Error>

%P

Source

fn fmt_ampm_upper(&mut self, ext: &Extension) -> Result<(), Error>

%p

Source

fn fmt_american_date(&mut self, ext: &Extension) -> Result<(), Error>

%D

Source

fn fmt_clock_nosecs(&mut self, ext: &Extension) -> Result<(), Error>

%R

Source

fn fmt_clock_secs(&mut self, ext: &Extension) -> Result<(), Error>

%T

Source

fn fmt_day_zero(&mut self, ext: &Extension) -> Result<(), Error>

%d

Source

fn fmt_day_space(&mut self, ext: &Extension) -> Result<(), Error>

%e

Source

fn fmt_hour12_zero(&mut self, ext: &Extension) -> Result<(), Error>

%I

Source

fn fmt_hour24_zero(&mut self, ext: &Extension) -> Result<(), Error>

%H

Source

fn fmt_hour12_space(&mut self, ext: &Extension) -> Result<(), Error>

%l

Source

fn fmt_hour24_space(&mut self, ext: &Extension) -> Result<(), Error>

%k

Source

fn fmt_iso_date(&mut self, ext: &Extension) -> Result<(), Error>

%F

Source

fn fmt_minute(&mut self, ext: &Extension) -> Result<(), Error>

%M

Source

fn fmt_month(&mut self, ext: &Extension) -> Result<(), Error>

%m

Source

fn fmt_month_full(&mut self, ext: &Extension) -> Result<(), Error>

%B

Source

fn fmt_month_abbrev(&mut self, ext: &Extension) -> Result<(), Error>

%b, %h

Source

fn fmt_iana_nocolon(&mut self) -> Result<(), Error>

%Q

Source

fn fmt_iana_colon(&mut self) -> Result<(), Error>

%:Q

Source

fn fmt_offset_nocolon(&mut self) -> Result<(), Error>

%z

Source

fn fmt_offset_colon(&mut self) -> Result<(), Error>

%:z

Source

fn fmt_offset_colon2(&mut self) -> Result<(), Error>

%::z

Source

fn fmt_offset_colon3(&mut self) -> Result<(), Error>

%:::z

Source

fn fmt_second(&mut self, ext: &Extension) -> Result<(), Error>

%S

Source

fn fmt_timestamp(&mut self, ext: &Extension) -> Result<(), Error>

%s

Source

fn fmt_fractional(&mut self, ext: &Extension) -> Result<(), Error>

%f

Source

fn fmt_dot_fractional(&mut self, ext: &Extension) -> Result<(), Error>

%.f

Source

fn fmt_nanoseconds(&mut self, ext: &Extension) -> Result<(), Error>

%N

Source

fn fmt_tzabbrev(&mut self, ext: &Extension) -> Result<(), Error>

%Z

Source

fn fmt_weekday_full(&mut self, ext: &Extension) -> Result<(), Error>

%A

Source

fn fmt_weekday_abbrev(&mut self, ext: &Extension) -> Result<(), Error>

%a

Source

fn fmt_weekday_mon(&mut self, ext: &Extension) -> Result<(), Error>

%u

Source

fn fmt_weekday_sun(&mut self, ext: &Extension) -> Result<(), Error>

%w

Source

fn fmt_week_sun(&mut self, ext: &Extension) -> Result<(), Error>

%U

Source

fn fmt_week_iso(&mut self, ext: &Extension) -> Result<(), Error>

%V

Source

fn fmt_week_mon(&mut self, ext: &Extension) -> Result<(), Error>

%W

Source

fn fmt_year(&mut self, ext: &Extension) -> Result<(), Error>

%Y

Source

fn fmt_year2(&mut self, ext: &Extension) -> Result<(), Error>

%y

Source

fn fmt_century(&mut self, ext: &Extension) -> Result<(), Error>

%C

Source

fn fmt_iso_week_year(&mut self, ext: &Extension) -> Result<(), Error>

%G

Source

fn fmt_iso_week_year2(&mut self, ext: &Extension) -> Result<(), Error>

%g

Source

fn fmt_quarter(&mut self, ext: &Extension) -> Result<(), Error>

%q

Source

fn fmt_day_of_year(&mut self, ext: &Extension) -> Result<(), Error>

%j

Source

fn fmt_literal(&mut self, literal: &str) -> Result<(), Error>

%n, %t

Source

fn fmt_datetime(&mut self, ext: &Extension) -> Result<(), Error>

%c

Source

fn fmt_date(&mut self, ext: &Extension) -> Result<(), Error>

%x

Source

fn fmt_time(&mut self, ext: &Extension) -> Result<(), Error>

%X

Source

fn fmt_12hour_time(&mut self, ext: &Extension) -> Result<(), Error>

%r

Auto Trait Implementations§

§

impl<'c, 'f, 't, 'w, W, L> Freeze for Formatter<'c, 'f, 't, 'w, W, L>

§

impl<'c, 'f, 't, 'w, W, L> RefUnwindSafe for Formatter<'c, 'f, 't, 'w, W, L>

§

impl<'c, 'f, 't, 'w, W, L> Send for Formatter<'c, 'f, 't, 'w, W, L>
where W: Send, L: Sync,

§

impl<'c, 'f, 't, 'w, W, L> Sync for Formatter<'c, 'f, 't, 'w, W, L>
where W: Sync, L: Sync,

§

impl<'c, 'f, 't, 'w, W, L> Unpin for Formatter<'c, 'f, 't, 'w, W, L>

§

impl<'c, 'f, 't, 'w, W, L> !UnwindSafe for Formatter<'c, 'f, 't, 'w, W, L>

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> 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, 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.