Skip to content

Commit 327f9e5

Browse files
authored
chore: use derive_more::IntoIterator (#6480)
1 parent ba74910 commit 327f9e5

File tree

2 files changed

+14
-50
lines changed

2 files changed

+14
-50
lines changed

src/blocks/tipset.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,21 @@ use thiserror::Error;
3030
/// Equal keys will have equivalent iteration order, but note that the `CIDs`
3131
/// are *not* maintained in the same order as the canonical iteration order of
3232
/// blocks in a tipset (which is by ticket)
33-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord, GetSize)]
33+
#[derive(
34+
Clone,
35+
Debug,
36+
PartialEq,
37+
Eq,
38+
Hash,
39+
Serialize,
40+
Deserialize,
41+
PartialOrd,
42+
Ord,
43+
GetSize,
44+
derive_more::IntoIterator,
45+
)]
3446
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
35-
pub struct TipsetKey(SmallCidNonEmptyVec);
47+
pub struct TipsetKey(#[into_iterator(owned, ref)] SmallCidNonEmptyVec);
3648

3749
impl TipsetKey {
3850
// Special encoding to match Lotus.
@@ -121,26 +133,6 @@ impl fmt::Display for TipsetKey {
121133
}
122134
}
123135

124-
impl<'a> IntoIterator for &'a TipsetKey {
125-
type Item = <&'a SmallCidNonEmptyVec as IntoIterator>::Item;
126-
127-
type IntoIter = <&'a SmallCidNonEmptyVec as IntoIterator>::IntoIter;
128-
129-
fn into_iter(self) -> Self::IntoIter {
130-
(&self.0).into_iter()
131-
}
132-
}
133-
134-
impl IntoIterator for TipsetKey {
135-
type Item = <SmallCidNonEmptyVec as IntoIterator>::Item;
136-
137-
type IntoIter = <SmallCidNonEmptyVec as IntoIterator>::IntoIter;
138-
139-
fn into_iter(self) -> Self::IntoIter {
140-
self.0.into_iter()
141-
}
142-
}
143-
144136
#[cfg(test)]
145137
impl Default for TipsetKey {
146138
fn default() -> Self {

src/cid_collections/hash_set.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,3 @@ impl FromIterator<Cid> for CidHashSet {
7373
this
7474
}
7575
}
76-
77-
pub struct IntoIter {
78-
inner: hash_map::IntoIter<()>,
79-
}
80-
81-
impl Iterator for IntoIter {
82-
type Item = Cid;
83-
84-
fn next(&mut self) -> Option<Self::Item> {
85-
self.inner.next().map(|(it, ())| it)
86-
}
87-
88-
fn size_hint(&self) -> (usize, Option<usize>) {
89-
self.inner.size_hint()
90-
}
91-
}
92-
93-
impl IntoIterator for CidHashSet {
94-
type Item = Cid;
95-
96-
type IntoIter = IntoIter;
97-
98-
fn into_iter(self) -> Self::IntoIter {
99-
IntoIter {
100-
inner: self.inner.into_iter(),
101-
}
102-
}
103-
}

0 commit comments

Comments
 (0)