steepen/
steepen.rs

1use crate::steepen_compat::SteepenCompat;
2use crate::Separator;
3use std::fmt::{Debug, Formatter};
4use std::marker::PhantomData;
5
6/// Iterator that yield blocks of elements in ascending order.
7///
8/// The block elements must implement [`FromIterator`]
9///
10/// This `struct` is created by the [`steepen`] method from [`Steepenable`] and the other similar
11/// methods. See its documentation for more.
12///
13/// [`Steepenable`]: crate::steepenable::Steepenable
14/// [`steepen`]: crate::steepenable::Steepenable::steepen()
15pub struct Steepen<I: Iterator, B> {
16	phantom: PhantomData<B>,
17	inner: SteepenCompat<I, B, Separator<I::Item>>,
18}
19
20impl<I: Iterator, B> Steepen<I, B>
21where
22	I::Item: Ord,
23{
24	#[inline]
25	pub(crate) fn new(iterator: I) -> Self {
26		Steepen {
27			phantom: Default::default(),
28			inner: SteepenCompat::new(iterator, |a, b| a > b),
29		}
30	}
31}
32
33impl<I: Iterator, B: FromIterator<I::Item>> Iterator for Steepen<I, B> {
34	type Item = B;
35
36	#[inline]
37	fn next(&mut self) -> Option<B> {
38		self.inner.next()
39	}
40}
41
42impl<I, B> Debug for Steepen<I, B>
43where
44	I: Debug + Iterator,
45	I::Item: Debug,
46{
47	#[inline]
48	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49		f.debug_struct("Steepen")
50			.field("inner", &self.inner)
51			.field("phantom", &self.phantom)
52			.finish()
53	}
54}