diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
commit | a0aa2307322cd47bbf416810ac0292925e03be87 (patch) | |
tree | 37076262a026c4b48c8a0e84f44ff9187556ca35 /rust/vendor/time/src/parsing/mod.rs | |
parent | Initial commit. (diff) | |
download | suricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip |
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/vendor/time/src/parsing/mod.rs')
-rw-r--r-- | rust/vendor/time/src/parsing/mod.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/rust/vendor/time/src/parsing/mod.rs b/rust/vendor/time/src/parsing/mod.rs new file mode 100644 index 0000000..4a2aa82 --- /dev/null +++ b/rust/vendor/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<U>(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<U>(self, f: impl FnOnce(T) -> Option<U>) -> Option<ParsedItem<'a, U>> { + 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 + } +} |