From a2cab3b1aca9b90037007bb2d69b7c1d7c8a43f7 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet <44676486+Philippe-Cholet@users.noreply.github.com> Date: Thu, 2 May 2024 11:11:26 +0200 Subject: [PATCH] `get`: when is it ESI and/or DEI --- src/lib.rs | 5 +++-- tests/test_core.rs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 37d64a160..c45f0cd07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. diff --git a/tests/test_core.rs b/tests/test_core.rs index b5826ef39..6f7dc1fda 100644 --- a/tests/test_core.rs +++ b/tests/test_core.rs @@ -18,6 +18,28 @@ use crate::it::Itertools; use core::iter; use itertools as it; +#[allow(dead_code)] +fn get_esi_then_esi(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(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!();