1//! Parsing for various types.
23pub(crate) mod combinator;
4pub(crate) mod component;
5mod iso8601;
6pub(crate) mod parsable;
7mod parsed;
8pub(crate) mod shim;
910pub use self::parsable::Parsable;
11pub use self::parsed::Parsed;
1213/// An item that has been parsed. Represented as a `(remaining, value)` pair.
14#[derive(#[automatically_derived]impl<'a, T: ::core::fmt::Debug> ::core::fmt::Debug for
ParsedItem<'a, T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "ParsedItem",
&self.0, &&self.1)
}
}Debug)]
15pub(crate) struct ParsedItem<'a, T>(pub(crate) &'a [u8], pub(crate) T);
1617impl<'a, T> ParsedItem<'a, T> {
18/// Map the value to a new value, preserving the remaining input.
19#[inline]
20pub(crate) fn map<U>(self, f: impl FnOnce(T) -> U) -> ParsedItem<'a, U> {
21ParsedItem(self.0, f(self.1))
22 }
2324/// Map the value to a new, optional value, preserving the remaining input.
25#[inline]
26pub(crate) fn flat_map<U>(self, f: impl FnOnce(T) -> Option<U>) -> Option<ParsedItem<'a, U>> {
27Some(ParsedItem(self.0, f(self.1)?))
28 }
2930/// Consume the stored value with the provided function. The remaining input is returned.
31#[must_use = "this returns the remaining input"]
32 #[inline]
33pub(crate) fn consume_value(self, f: impl FnOnce(T) -> Option<()>) -> Option<&'a [u8]> {
34 f(self.1)?;
35Some(self.0)
36 }
3738/// Discard the stored value, returning the remaining input.
39#[must_use = "this returns the remaining input"]
40 #[inline]
41pub(crate) fn discard_value(self) -> &'a [u8] {
42self.0
43}
4445/// Filter the value with the provided function. If the function returns `false`, the value
46 /// is discarded and `None` is returned. Otherwise, the value is preserved and `Some(self)` is
47 /// returned.
48#[inline]
49pub(crate) fn filter(self, f: impl FnOnce(&T) -> bool) -> Option<Self> {
50f(&self.1).then_some(self)
51 }
52}
5354impl<'a> ParsedItem<'a, ()> {
55/// Discard the unit value, returning the remaining input.
56#[must_use = "this returns the remaining input"]
57 #[inline]
58pub(crate) const fn into_inner(self) -> &'a [u8] {
59self.0
60}
61}