pub struct DateFormat { /* private fields */ }Expand description
A source’s spelling, read once.
Built from the authored text and never rebuilt: every engine translates the same list, so two engines cannot disagree about what the design said.
Implementations§
Source§impl DateFormat
impl DateFormat
Sourcepub fn parse(spelled: &str) -> Result<Self, DateFormatError>
pub fn parse(spelled: &str) -> Result<Self, DateFormatError>
Read a format, or say what is wrong with it.
§Errors
A % followed by a letter outside the family, a % at the end with
nothing after it, or nothing at all.
Sourcepub fn parts(&self) -> &[FormatPart]
pub fn parts(&self) -> &[FormatPart]
The pieces, in the order the value writes them.
Sourcepub fn directives(&self) -> impl Iterator<Item = FormatDirective> + '_
pub fn directives(&self) -> impl Iterator<Item = FormatDirective> + '_
Every directive the format says, in order, literals passed over.
Sourcepub fn names_a_zone(&self) -> bool
pub fn names_a_zone(&self) -> bool
True where the format carries an offset or a zone name — the two things a column holding a day alone has nowhere to put.
Sourcepub fn says_a_time_of_day(&self) -> bool
pub fn says_a_time_of_day(&self) -> bool
True where the format says anything about the time within a day.
Sourcepub fn translate(
&self,
spell: &dyn Fn(FormatDirective) -> Option<&'static str>,
literal: &dyn Fn(&str) -> String,
) -> Result<String, FormatDirective>
pub fn translate( &self, spell: &dyn Fn(FormatDirective) -> Option<&'static str>, literal: &dyn Fn(&str) -> String, ) -> Result<String, FormatDirective>
Translate the format into one engine’s own pattern language, directive by directive.
spell answers with this engine’s token for one directive, or None
where the engine has no way to say it; literal writes a run of
literal text the way this engine’s patterns want it, which on some is
the text as it stands and on others is the text in quotes.
§Errors
The first directive spell answered None for — which is what the
refusal names, so an author is told which part of their format this
engine cannot read rather than that the format failed.
Sourcepub fn shape_pattern(&self) -> String
pub fn shape_pattern(&self) -> String
A guard against a value spelled some other way, as an anchored POSIX regular expression that holds every field to its own range.
It is for the engines that read a value they cannot read: hand
13/45/2015 to a parse that rolls fields over and it answers a day in
2016 rather than answering nothing. The guard is built from the same
list the parse is, so the two cannot disagree about what the design
said.
What it holds and what it does not. Every field is held to its own range — a month is 1 to 12, an hour is 0 to 23 — so a value written some other way, or holding a number no calendar has, is caught. A day that is in range and yet not in its month, the thirty-first of a thirty-day month, is not a question a shape can answer; the engines that need this guard say in their own rendering what they do about it.
Sourcepub fn capture_pattern(&self, wanted: FormatDirective) -> Option<String>
pub fn capture_pattern(&self, wanted: FormatDirective) -> Option<String>
Read one field back out of the value, as an anchored POSIX regular expression with exactly one capturing group around the field asked for.
Everything else in it is loose and ungrouped, so the group an engine reads back is the first one and the only one — which is the most any of the engines needing it can address.
None where the format does not say that field at all.
Trait Implementations§
Source§impl Clone for DateFormat
impl Clone for DateFormat
Source§fn clone(&self) -> DateFormat
fn clone(&self) -> DateFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more