Skip to main content

Parse

Struct Parse 

Source
pub struct Parse<'z, Tz2> { /* private fields */ }
Expand description

Parse struct has methods implemented parsers for accepted formats.

Implementations§

Source§

impl<'z, Tz2> Parse<'z, Tz2>
where Tz2: TimeZone,

Source

pub const fn new(tz: &'z Tz2, default_time: NaiveTime) -> Self

Create a new instance of Parse with a custom parsing timezone that handles the datetime string without time offset.

Source

pub const fn prefer_dmy(&mut self, yes: bool) -> &Self

Source

pub const fn new_with_preference( tz: &'z Tz2, default_time: NaiveTime, prefer_dmy: bool, ) -> Self

Create a new instance of Parse with a custom parsing timezone that handles the datetime string without time offset, and the date parsing preference.

Source

pub fn parse(&self, input: &str) -> Result<DateTime<Utc>>

This method tries to parse the input datetime string with a list of accepted formats. See more examples from Parse, crate::parse() and crate::parse_with_timezone().

Order rationale: the regex-gated families are tried first because their is_match gate rejects non-matching inputs cheaply. The two parsers without a family regex gate — unix_timestamp (runs fast_float2) and rfc2822 (runs parse_from_rfc2822) — are tried last to avoid paying their cost on the common ISO/slash dates. Each still applies its own cheap byte pre-filter before the heavy parse (unix_timestamp checks the first byte against the leads fast_float2 accepts; rfc2822 requires a :).

This reorder is result-preserving:

  • A fast_float2-parseable input (a pure finite number; inf/nan are rejected as non-finite) matches no family gate (they all require /, an interior -, or a letters+space shape a bare number lacks), so it still reaches unix_timestamp.
  • An rfc2822 input always carries a timezone, which makes the $-anchored month_dmy_* regexes fail; conversely month_dmy_* only succeeds without a timezone, which makes rfc2822 fail. The two are mutually exclusive, so deferring rfc2822 cannot change any result.

Within that order, the first byte selects which families can match at all. Every family gate is ^-anchored on either a digit or a letter, so a letter-leading input cannot match any of the numeric families and vice versa. Running them anyway costs roughly 5-10 ns each in regex startup even when the first byte rejects immediately, which is most of the cost of a non-date word — the dominant input in a qsv stats --infer-dates run over a text column.

rfc2822 stays in the digit branch as well as the letter branch: the day-of-week is optional in RFC 2822, so 02 Jun 2021 06:31:39 GMT parses and leads with a digit.

Auto Trait Implementations§

§

impl<'z, Tz2> Freeze for Parse<'z, Tz2>
where &'z Tz2: Freeze,

§

impl<'z, Tz2> RefUnwindSafe for Parse<'z, Tz2>

§

impl<'z, Tz2> Send for Parse<'z, Tz2>
where &'z Tz2: Send,

§

impl<'z, Tz2> Sync for Parse<'z, Tz2>
where &'z Tz2: Sync,

§

impl<'z, Tz2> Unpin for Parse<'z, Tz2>
where &'z Tz2: Unpin,

§

impl<'z, Tz2> UnsafeUnpin for Parse<'z, Tz2>

§

impl<'z, Tz2> UnwindSafe for Parse<'z, Tz2>

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 = !

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.