better-url 0.12.0

A better URL crate.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! [`IteratorExt`].

/// [`Iterator`] extension trait.
pub(crate) trait IteratorExt: Iterator {
    /// Get the `n`th element.
    /// # Errors
    /// If fewer than `n` elements are available, returns the missing amount as an error.
    fn try_nth(&mut self, n: usize) -> Result<Self::Item, usize>;
}

impl<I: Iterator> IteratorExt for I {
    fn try_nth(&mut self, n: usize) -> Result<Self::Item, usize> {
        match n - self.take(n).count() {
            0 => self.next().ok_or(0),
            x => Err(x)
        }
    }
}