1
//! Misc helper functions and types for use in parsing network documents
2

            
3
pub(crate) mod str;
4

            
5
pub mod batching_split_before;
6

            
7
use std::iter::Peekable;
8

            
9
/// An iterator with a `.peek()` method
10
///
11
/// We make this a trait to avoid entangling all the types with `Peekable`.
12
/// Ideally we would do this with `Itertools::PeekingNext`
13
/// but that was not implemented for `&mut PeekingNext`
14
/// when we wrote this code,
15
/// and we need that because we use a lot of `&mut NetdocReader`.
16
/// <https://github.com/rust-itertools/itertools/issues/678>
17
///
18
/// TODO: As of itertools 0.11.0, `PeekingNext` _is_ implemented for
19
/// `&'a mut I where I: PeekingNext`, so we can remove this type some time.
20
///
21
/// # **UNSTABLE**
22
///
23
/// This type is UNSTABLE and not part of the semver guarantees.
24
/// You'll only see it if you ran rustdoc with `--document-private-items`.
25
// This is needed because this is a trait bound for batching_split_before.
26
#[doc(hidden)]
27
pub trait PeekableIterator: Iterator {
28
    /// Inspect the next item, if there is one
29
    fn peek(&mut self) -> Option<&Self::Item>;
30
}
31

            
32
impl<I: Iterator> PeekableIterator for Peekable<I> {
33
    fn peek(&mut self) -> Option<&Self::Item> {
34
        self.peek()
35
    }
36
}
37

            
38
impl<I: PeekableIterator> PeekableIterator for &mut I {
39
10088
    fn peek(&mut self) -> Option<&Self::Item> {
40
10088
        <I as PeekableIterator>::peek(*self)
41
10088
    }
42
}
43

            
44
/// A Private module for declaring a "sealed" trait.
45
pub(crate) mod private {
46
    /// A non-exported trait, used to prevent others from implementing a trait.
47
    ///
48
    /// For more information on this pattern, see [the Rust API
49
    /// guidelines](https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed).
50
    #[expect(dead_code, unreachable_pub)] // TODO keep this Sealed trait in case we want it again?
51
    pub trait Sealed {}
52
}