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!();