Skip to content

Commit 97c74c3

Browse files
Small fixes
Fix my own review, update docs and fix a warning with `#[cfg(doc)]`.
1 parent 282e867 commit 97c74c3

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/iter_index.rs

+5-6
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

+9-9
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,14 @@ pub trait Itertools: Iterator {
505505
intersperse::intersperse_with(self, element)
506506
}
507507

508-
/// Returns an element at a specific location, or returns an iterator
509-
/// over a subsection of the iterator.
508+
/// Returns an iterator over a subsection of the iterator.
510509
///
511510
/// Works similarly to [`slice::get`](https://doc.rust-lang.org/std/primitive.slice.html#method.get).
512511
///
513-
/// It's a generalisation of [`take`], [`skip`] and [`nth`], and uses these
514-
/// under the hood.
512+
/// It's a generalisation of [`Iterator::take`] and [`Iterator::skip`],
513+
/// and uses these under the hood.
514+
/// Therefore, the resulting iterator is [`DoubleEndedIterator`]
515+
/// and/or [`ExactSizeIterator`] if the adapted iterator is.
515516
///
516517
/// # Unspecified Behavior
517518
/// The result of indexing with an exhausted [`core::ops::RangeInclusive`] is unspecified.
@@ -524,7 +525,7 @@ pub trait Itertools: Iterator {
524525
/// let vec = vec![3, 1, 4, 1, 5];
525526
///
526527
/// let mut range: Vec<_> =
527-
/// vec.iter().get(1..=3).copied().collect();
528+
/// vec.iter().get(1..=3).copied().collect();
528529
/// assert_eq!(&range, &[1, 4, 1]);
529530
///
530531
/// // It works with other types of ranges, too
@@ -537,13 +538,12 @@ pub trait Itertools: Iterator {
537538
/// range = vec.iter().get(2..).copied().collect();
538539
/// assert_eq!(&range, &[4, 1, 5]);
539540
///
541+
/// range = vec.iter().get(..=2).copied().collect();
542+
/// assert_eq!(&range, &[3, 1, 4]);
543+
///
540544
/// range = vec.iter().get(..).copied().collect();
541545
/// assert_eq!(range, vec);
542546
/// ```
543-
///
544-
/// [`take`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.take
545-
/// [`skip`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.skip
546-
/// [`nth`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.nth
547547
fn get<R>(self, index: R) -> R::Output
548548
where
549549
Self: Sized,

0 commit comments

Comments
 (0)