pub(crate) trait IteratorExt: Iterator {
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)
}
}
}