Skip to content

Commit 38ec020

Browse files
Philippe-Choletjswrenn
authored andcommitted
Small fixes
Fix my own review. Update docs. Fix a warning with `#[cfg(doc)]`. Use public path `traits::IteratorIndex` instead of private path `iter_index::IteratorIndex`.
1 parent 24f31de commit 38ec020

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/iter_index.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use core::iter::{Skip, Take};
22
use core::ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive};
33

4+
#[cfg(doc)]
45
use crate::Itertools;
56

67
mod private_iter_index {
@@ -16,17 +17,16 @@ mod private_iter_index {
1617
impl Sealed for ops::RangeFull {}
1718
}
1819

19-
/// Used by the ``range`` function to know which iterator
20+
/// Used by [`get`] and [`Itertools::get`] to know which iterator
2021
/// to turn different ranges into.
2122
pub trait IteratorIndex<I>: private_iter_index::Sealed
2223
where
2324
I: Iterator,
2425
{
25-
/// The type that [`get`] or [`Itertools::get`]
26-
/// returns when called with this type of index.
26+
/// The type returned for this type of index.
2727
type Output: Iterator<Item = I::Item>;
2828

29-
/// Returns an iterator(or value) in the specified range.
29+
/// Returns an adapted iterator for the current index.
3030
///
3131
/// Prefer calling [`get`] or [`Itertools::get`] instead
3232
/// of calling this directly.
@@ -102,8 +102,7 @@ where
102102
}
103103
}
104104

105-
/// Returns an element of the iterator or an iterator
106-
/// over a subsection of the iterator.
105+
/// Returns an iterator over a subsection of the iterator.
107106
///
108107
/// See [`Itertools::get`] for more information.
109108
pub fn get<I, R>(iter: I, index: R) -> R::Output

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,14 @@ pub trait Itertools: Iterator {
507507
intersperse::intersperse_with(self, element)
508508
}
509509

510-
/// Returns an element at a specific location, or returns an iterator
511-
/// over a subsection of the iterator.
510+
/// Returns an iterator over a subsection of the iterator.
512511
///
513512
/// Works similarly to [`slice::get`](https://doc.rust-lang.org/std/primitive.slice.html#method.get).
514513
///
515-
/// It's a generalisation of [`take`], [`skip`] and [`nth`], and uses these
516-
/// under the hood.
514+
/// It's a generalisation of [`Iterator::take`] and [`Iterator::skip`],
515+
/// and uses these under the hood.
516+
/// Therefore, the resulting iterator is [`DoubleEndedIterator`]
517+
/// and/or [`ExactSizeIterator`] if the adapted iterator is.
517518
///
518519
/// # Unspecified Behavior
519520
/// The result of indexing with an exhausted [`core::ops::RangeInclusive`] is unspecified.
@@ -526,7 +527,7 @@ pub trait Itertools: Iterator {
526527
/// let vec = vec![3, 1, 4, 1, 5];
527528
///
528529
/// let mut range: Vec<_> =
529-
/// vec.iter().get(1..=3).copied().collect();
530+
/// vec.iter().get(1..=3).copied().collect();
530531
/// assert_eq!(&range, &[1, 4, 1]);
531532
///
532533
/// // It works with other types of ranges, too
@@ -539,17 +540,16 @@ pub trait Itertools: Iterator {
539540
/// range = vec.iter().get(2..).copied().collect();
540541
/// assert_eq!(&range, &[4, 1, 5]);
541542
///
543+
/// range = vec.iter().get(..=2).copied().collect();
544+
/// assert_eq!(&range, &[3, 1, 4]);
545+
///
542546
/// range = vec.iter().get(..).copied().collect();
543547
/// assert_eq!(range, vec);
544548
/// ```
545-
///
546-
/// [`take`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.take
547-
/// [`skip`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.skip
548-
/// [`nth`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.nth
549549
fn get<R>(self, index: R) -> R::Output
550550
where
551551
Self: Sized,
552-
R: iter_index::IteratorIndex<Self>,
552+
R: traits::IteratorIndex<Self>,
553553
{
554554
iter_index::get(self, index)
555555
}

0 commit comments

Comments
 (0)