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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! A collection of iterators and traits that allow you to get _owned_ chunks
//! from collections (currently [`Vec`](std::vec::Vec) and [`array`](prim@array))
//!
//! # Example
//! ```rust
//! use owned_chunks::OwnedChunks;
//!
//! fn take_ownership(v: Vec<i32>) {
//! // implementation
//! }
//!
//! for (ix, chunk) in vec![vec![1, 2], vec![3, 4], vec![5, 6]].owned_chunks(2).enumerate() {
//! match ix {
//! 0 => assert_eq!(&[vec![1, 2], vec![3, 4]], chunk.as_slice()),
//! 1 => assert_eq!(&[vec![5, 6]], chunk.as_slice()),
//! _ => panic!("no more chunks expected"),
//! }
//!
//! for vec in chunk {
//! take_ownership(vec);
//! }
//! }
//! ```
/// chunk iterators for [`arrays`](prim@array)
/// chunk iterators for [`Vecs`](Vec)
/// A trait to get _owned_ chunks from a collection.
/// This is very similar to the [`slice::*chunks*`](slice::chunks) family of functions except that the chunks will
/// not be references/slices into the storage but iterators that yield the owned items inside it.
///
/// # Note
/// Although there exists an implementation of [`OwnedChunks`] for [`arrays`](prim@array) you should always [**\*1**]
/// prefer [`StaticOwnedChunks`] if possible, due to how this is implemented for them.
/// (See [`array::ArrayChunks#Implementation details`] for more information)
///
/// **\*1**: For small [`arrays`](prim@array) the performance penalty should be negligible so it is probably fine for those.
///
/// # Example
/// Demonstaration of simmilarity to slice functions
///
/// ```rust
/// use owned_chunks::OwnedChunks;
///
/// for (ix, chunk) in vec![1, 2, 3, 4, 5].owned_chunks(2).enumerate() {
/// let expected: &[i32] = match ix {
/// 0 => &[1, 2],
/// 1 => &[3, 4],
/// 2 => &[5],
/// _ => panic!("no more chunks expected"),
/// };
/// assert_eq!(expected, chunk.as_slice());
/// }
/// ```
///
/// # Example
/// Ownership transfer
///
/// ```rust
/// use owned_chunks::OwnedChunks;
///
/// fn take_ownership(v: Vec<i32>) {
/// // some implementation
/// }
///
/// for chunk in vec![vec![1, 2, 3]; 10].owned_chunks(4) {
/// for vec in chunk {
/// take_ownership(vec);
/// }
/// }
/// ```
/// A variant of [`OwnedChunks`] with const chunk size; this primarily exists to allow storage size
/// optimizations for types where storage size depends on a constant, like [`arrays`](prim@array). For further
/// information see the docs of [`array::ArrayChunks#Implementation details`].
///
/// # Example
/// ```rust
/// use owned_chunks::StaticOwnedChunks;
///
/// fn take_ownership(v: Vec<i32>) {
/// // some implementation
/// }
///
/// for chunk in [vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]].static_owned_chunks::<2>() {
/// for v in chunk {
/// take_ownership(v);
/// }
/// }
/// ```
///