Skip to content

Commit 97dbaea

Browse files
committed
Fix clippy::type_complexity in iterators
1 parent 26b5293 commit 97dbaea

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

src/map/iter.rs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ pub(crate) struct Buckets<'a, K, V> {
4343

4444
impl<'a, K, V> Buckets<'a, K, V> {
4545
pub(crate) fn new(entries: &'a VecDeque<Bucket<K, V>>) -> Self {
46-
Self::from_slices(entries.as_slices())
47-
}
48-
49-
pub(crate) fn from_slices((head, tail): (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
46+
let (head, tail) = entries.as_slices();
5047
Self {
5148
head: head.iter(),
5249
tail: tail.iter(),
5350
}
5451
}
52+
53+
pub(crate) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
54+
Self {
55+
head: slice.iter(),
56+
tail: [].iter(),
57+
}
58+
}
5559
}
5660

5761
impl<'a, K, V> Iterator for Buckets<'a, K, V> {
@@ -148,18 +152,25 @@ struct BucketsMut<'a, K, V> {
148152

149153
impl<'a, K, V> BucketsMut<'a, K, V> {
150154
fn new(entries: &'a mut VecDeque<Bucket<K, V>>) -> Self {
151-
Self::from_mut_slices(entries.as_mut_slices())
152-
}
153-
154-
fn from_mut_slices((head, tail): (&'a mut [Bucket<K, V>], &'a mut [Bucket<K, V>])) -> Self {
155+
let (head, tail) = entries.as_mut_slices();
155156
Self {
156157
head: head.iter_mut(),
157158
tail: tail.iter_mut(),
158159
}
159160
}
160161

162+
fn from_mut_slice(slice: &'a mut [Bucket<K, V>]) -> Self {
163+
Self {
164+
head: slice.iter_mut(),
165+
tail: [].iter_mut(),
166+
}
167+
}
168+
161169
fn iter(&self) -> Buckets<'_, K, V> {
162-
Buckets::from_slices((self.head.as_slice(), self.tail.as_slice()))
170+
Buckets {
171+
head: self.head.as_slice().iter(),
172+
tail: self.tail.as_slice().iter(),
173+
}
163174
}
164175
}
165176

@@ -255,9 +266,9 @@ impl<'a, K, V> Iter<'a, K, V> {
255266
}
256267
}
257268

258-
pub(super) fn from_slices(slices: (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
269+
pub(super) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
259270
Self {
260-
iter: Buckets::from_slices(slices),
271+
iter: Buckets::from_slice(slice),
261272
}
262273
}
263274
}
@@ -318,11 +329,9 @@ impl<'a, K, V> IterMut<'a, K, V> {
318329
}
319330
}
320331

321-
pub(super) fn from_mut_slices(
322-
slices: (&'a mut [Bucket<K, V>], &'a mut [Bucket<K, V>]),
323-
) -> Self {
332+
pub(super) fn from_mut_slice(slice: &'a mut [Bucket<K, V>]) -> Self {
324333
Self {
325-
iter: BucketsMut::from_mut_slices(slices),
334+
iter: BucketsMut::from_mut_slice(slice),
326335
}
327336
}
328337
}
@@ -517,9 +526,9 @@ impl<'a, K, V> Keys<'a, K, V> {
517526
}
518527
}
519528

520-
pub(super) fn from_slices(slices: (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
529+
pub(super) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
521530
Self {
522-
iter: Buckets::from_slices(slices),
531+
iter: Buckets::from_slice(slice),
523532
}
524533
}
525534
}
@@ -705,9 +714,9 @@ impl<'a, K, V> Values<'a, K, V> {
705714
}
706715
}
707716

708-
pub(super) fn from_slices(slices: (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
717+
pub(super) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
709718
Self {
710-
iter: Buckets::from_slices(slices),
719+
iter: Buckets::from_slice(slice),
711720
}
712721
}
713722
}
@@ -768,11 +777,9 @@ impl<'a, K, V> ValuesMut<'a, K, V> {
768777
}
769778
}
770779

771-
pub(super) fn from_mut_slices(
772-
slices: (&'a mut [Bucket<K, V>], &'a mut [Bucket<K, V>]),
773-
) -> Self {
780+
pub(super) fn from_mut_slice(slice: &'a mut [Bucket<K, V>]) -> Self {
774781
Self {
775-
iter: BucketsMut::from_mut_slices(slices),
782+
iter: BucketsMut::from_mut_slice(slice),
776783
}
777784
}
778785
}

src/map/slice.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ impl<K, V> Slice<K, V> {
173173

174174
/// Return an iterator over the key-value pairs of the map slice.
175175
pub fn iter(&self) -> Iter<'_, K, V> {
176-
Iter::from_slices((&self.entries, &[]))
176+
Iter::from_slice(&self.entries)
177177
}
178178

179179
/// Return an iterator over the key-value pairs of the map slice.
180180
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
181-
IterMut::from_mut_slices((&mut self.entries, &mut []))
181+
IterMut::from_mut_slice(&mut self.entries)
182182
}
183183

184184
/// Return an iterator over the keys of the map slice.
185185
pub fn keys(&self) -> Keys<'_, K, V> {
186-
Keys::from_slices((&self.entries, &[]))
186+
Keys::from_slice(&self.entries)
187187
}
188188

189189
/// Return an owning iterator over the keys of the map slice.
@@ -193,12 +193,12 @@ impl<K, V> Slice<K, V> {
193193

194194
/// Return an iterator over the values of the map slice.
195195
pub fn values(&self) -> Values<'_, K, V> {
196-
Values::from_slices((&self.entries, &[]))
196+
Values::from_slice(&self.entries)
197197
}
198198

199199
/// Return an iterator over mutable references to the the values of the map slice.
200200
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
201-
ValuesMut::from_mut_slices((&mut self.entries, &mut []))
201+
ValuesMut::from_mut_slice(&mut self.entries)
202202
}
203203

204204
/// Return an owning iterator over the values of the map slice.

src/set/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ impl<'a, T> Iter<'a, T> {
4040
}
4141
}
4242

43-
pub(super) fn from_slices(slices: (&'a [Bucket<T>], &'a [Bucket<T>])) -> Self {
43+
pub(super) fn from_slice(slice: &'a [Bucket<T>]) -> Self {
4444
Self {
45-
iter: Buckets::from_slices(slices),
45+
iter: Buckets::from_slice(slice),
4646
}
4747
}
4848
}

src/set/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<T> Slice<T> {
109109

110110
/// Return an iterator over the values of the set slice.
111111
pub fn iter(&self) -> Iter<'_, T> {
112-
Iter::from_slices((&self.entries, &[]))
112+
Iter::from_slice(&self.entries)
113113
}
114114

115115
/// Search over a sorted set for a value.

0 commit comments

Comments
 (0)