struct Extension {
flag: Option<Flag>,
width: Option<u8>,
}
Expand description
These are “extensions” to the standard strftime
conversion specifiers.
Basically, these provide control over padding (zeros, spaces or none), how much to pad and the case of string enumerations.
Fields§
§flag: Option<Flag>
§width: Option<u8>
Implementations§
Source§impl Extension
impl Extension
Sourcefn write_str<W: Write>(
self,
default: Case,
string: &str,
wtr: &mut W,
) -> Result<(), Error>
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§impl Extension
impl Extension
Sourcefn parse_number<'i>(
self,
default_pad_width: usize,
default_flag: Flag,
inp: &'i [u8],
) -> Result<(i64, &'i [u8]), Error>
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
impl Extension
Sourcefn parse_flag<'i>(fmt: &'i [u8]) -> Result<(Option<Flag>, &'i [u8]), Error>
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.
Sourcefn parse_width<'i>(fmt: &'i [u8]) -> Result<(Option<u8>, &'i [u8]), Error>
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.