1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Materialize lazy iterators into owned, concrete iterators.
//!
//! This module provides the [`Intermediate`] trait, which allows breaking iterator chains by
//! collecting elements into a temporary buffer and returning a new owned iterator. This is useful
//! when you need to decouple borrowing, iterate multiple times over the same elements, or simply
//! force evaluation of a lazy iterator at a specific point in a chain.
//!
//! The intermediate buffer uses [`SmallVec`] internally, so small sequences avoid heap allocation
//! entirely.
//!
//! # Example
//!
//! ```rust,no_run
//! # use zhc_utils::iter::Intermediate;
//! // Break an iterator chain to release borrows early
//! let data = vec![1, 2, 3, 4, 5];
//! let doubled: Vec<_> = data.iter()
//! .map(|x| x * 2)
//! .intermediate() // materializes here, releasing borrow on `data`
//! .filter(|&x| x > 4)
//! .collect();
//! ```
//!
//! [`SmallVec`]: crate::small::SmallVec
use crate::;
/// Extension trait for materializing a lazy iterator into an owned iterator.
///
/// This trait is automatically implemented for all iterators, providing the
/// [`intermediate`](Self::intermediate) method to collect elements into a temporary buffer and
/// yield them through a new owned iterator. The resulting [`SmallVecIntoIter`] implements
/// [`DoubleEndedIterator`], so you can traverse elements in reverse after materialization.
///
/// [`SmallVecIntoIter`]: crate::small::SmallVecIntoIter