Skip to content

Commit 3c16f14

Browse files
Philippe-Choletjswrenn
authored andcommitted
get: when is it ESI and/or DEI
1 parent 4dd6ba0 commit 3c16f14

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,9 @@ pub trait Itertools: Iterator {
515515
///
516516
/// It's a generalisation of [`Iterator::take`] and [`Iterator::skip`],
517517
/// and uses these under the hood.
518-
/// Therefore, the resulting iterator is [`DoubleEndedIterator`]
519-
/// and/or [`ExactSizeIterator`] if the adapted iterator is.
518+
/// Therefore, the resulting iterator is:
519+
/// - [`ExactSizeIterator`] if the adapted iterator is [`ExactSizeIterator`].
520+
/// - [`DoubleEndedIterator`] if the adapted iterator is [`DoubleEndedIterator`] and [`ExactSizeIterator`].
520521
///
521522
/// # Unspecified Behavior
522523
/// The result of indexing with an exhausted [`core::ops::RangeInclusive`] is unspecified.

tests/test_core.rs

+22
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@ use crate::it::Itertools;
1818
use core::iter;
1919
use itertools as it;
2020

21+
#[allow(dead_code)]
22+
fn get_esi_then_esi<I: ExactSizeIterator + Clone>(it: I) {
23+
fn is_esi(_: impl ExactSizeIterator) {}
24+
is_esi(it.clone().get(1..4));
25+
is_esi(it.clone().get(1..=4));
26+
is_esi(it.clone().get(1..));
27+
is_esi(it.clone().get(..4));
28+
is_esi(it.clone().get(..=4));
29+
is_esi(it.get(..));
30+
}
31+
32+
#[allow(dead_code)]
33+
fn get_dei_esi_then_dei_esi<I: DoubleEndedIterator + ExactSizeIterator + Clone>(it: I) {
34+
fn is_dei_esi(_: impl DoubleEndedIterator + ExactSizeIterator) {}
35+
is_dei_esi(it.clone().get(1..4));
36+
is_dei_esi(it.clone().get(1..=4));
37+
is_dei_esi(it.clone().get(1..));
38+
is_dei_esi(it.clone().get(..4));
39+
is_dei_esi(it.clone().get(..=4));
40+
is_dei_esi(it.get(..));
41+
}
42+
2143
#[test]
2244
fn product0() {
2345
let mut prod = iproduct!();

0 commit comments

Comments
 (0)