Skip to content

Commit

Permalink
get: when is it ESI and/or DEI
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed May 2, 2024
1 parent e939728 commit b891b69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,9 @@ pub trait Itertools: Iterator {
///
/// It's a generalisation of [`Iterator::take`] and [`Iterator::skip`],
/// and uses these under the hood.
/// Therefore, the resulting iterator is [`DoubleEndedIterator`]
/// and/or [`ExactSizeIterator`] if the adapted iterator is.
/// Therefore, the resulting iterator is:
/// - [`ExactSizeIterator`] if the adapted iterator is [`ExactSizeIterator`].
/// - [`DoubleEndedIterator`] if the adapted iterator is [`DoubleEndedIterator`] and [`ExactSizeIterator`].
///
/// # Unspecified Behavior
/// The result of indexing with an exhausted [`core::ops::RangeInclusive`] is unspecified.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ use crate::it::Itertools;
use core::iter;
use itertools as it;

#[allow(dead_code)]
fn get_esi_then_esi<I: ExactSizeIterator + Clone>(it: I) {
fn is_esi(_: impl ExactSizeIterator) {}
is_esi(it.clone().get(1..4));
is_esi(it.clone().get(1..=4));
is_esi(it.clone().get(1..));
is_esi(it.clone().get(..4));
is_esi(it.clone().get(..=4));
is_esi(it.get(..));
}

#[allow(dead_code)]
fn get_dei_esi_then_dei_esi<I: DoubleEndedIterator + ExactSizeIterator + Clone>(it: I) {
fn is_dei_esi(_: impl DoubleEndedIterator + ExactSizeIterator) {}
is_dei_esi(it.clone().get(1..4));
is_dei_esi(it.clone().get(1..=4));
is_dei_esi(it.clone().get(1..));
is_dei_esi(it.clone().get(..4));
is_dei_esi(it.clone().get(..=4));
is_dei_esi(it.get(..));
}

#[test]
fn product0() {
let mut prod = iproduct!();
Expand Down

0 comments on commit b891b69

Please sign in to comment.