From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/time/src/parsing/mod.rs | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 third_party/rust/time/src/parsing/mod.rs (limited to 'third_party/rust/time/src/parsing/mod.rs') diff --git a/third_party/rust/time/src/parsing/mod.rs b/third_party/rust/time/src/parsing/mod.rs new file mode 100644 index 0000000000..4a2aa829f1 --- /dev/null +++ b/third_party/rust/time/src/parsing/mod.rs @@ -0,0 +1,50 @@ +//! Parsing for various types. + +pub(crate) mod combinator; +pub(crate) mod component; +mod iso8601; +pub(crate) mod parsable; +mod parsed; +pub(crate) mod shim; + +pub use self::parsable::Parsable; +pub use self::parsed::Parsed; + +/// An item that has been parsed. Represented as a `(remaining, value)` pair. +#[derive(Debug)] +pub(crate) struct ParsedItem<'a, T>(pub(crate) &'a [u8], pub(crate) T); + +impl<'a, T> ParsedItem<'a, T> { + /// Map the value to a new value, preserving the remaining input. + pub(crate) fn map(self, f: impl FnOnce(T) -> U) -> ParsedItem<'a, U> { + ParsedItem(self.0, f(self.1)) + } + + /// Map the value to a new, optional value, preserving the remaining input. + pub(crate) fn flat_map(self, f: impl FnOnce(T) -> Option) -> Option> { + Some(ParsedItem(self.0, f(self.1)?)) + } + + /// Consume the stored value with the provided function. The remaining input is returned. + #[must_use = "this returns the remaining input"] + pub(crate) fn consume_value(self, f: impl FnOnce(T) -> Option<()>) -> Option<&'a [u8]> { + f(self.1)?; + Some(self.0) + } +} + +impl<'a> ParsedItem<'a, ()> { + /// Discard the unit value, returning the remaining input. + #[must_use = "this returns the remaining input"] + pub(crate) const fn into_inner(self) -> &'a [u8] { + self.0 + } +} + +impl<'a> ParsedItem<'a, Option<()>> { + /// Discard the potential unit value, returning the remaining input. + #[must_use = "this returns the remaining input"] + pub(crate) const fn into_inner(self) -> &'a [u8] { + self.0 + } +} -- cgit v1.2.3