From b921609f39cce28aa96dcc00b8a7e260f9273515 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Mon, 26 Jan 2026 14:44:14 +0100 Subject: [PATCH 1/2] chore: use `derive_more::IntoIterator` --- src/blocks/tipset.rs | 36 +++++++++++++-------------------- src/cid_collections/hash_set.rs | 30 +-------------------------- 2 files changed, 15 insertions(+), 51 deletions(-) diff --git a/src/blocks/tipset.rs b/src/blocks/tipset.rs index e43202cdfe2..169351bc26c 100644 --- a/src/blocks/tipset.rs +++ b/src/blocks/tipset.rs @@ -30,9 +30,21 @@ use thiserror::Error; /// Equal keys will have equivalent iteration order, but note that the `CIDs` /// are *not* maintained in the same order as the canonical iteration order of /// blocks in a tipset (which is by ticket) -#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord, GetSize)] +#[derive( + Clone, + Debug, + PartialEq, + Eq, + Hash, + Serialize, + Deserialize, + PartialOrd, + Ord, + GetSize, + derive_more::IntoIterator, +)] #[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))] -pub struct TipsetKey(SmallCidNonEmptyVec); +pub struct TipsetKey(#[into_iterator(owned, ref)] SmallCidNonEmptyVec); impl TipsetKey { // Special encoding to match Lotus. @@ -121,26 +133,6 @@ impl fmt::Display for TipsetKey { } } -impl<'a> IntoIterator for &'a TipsetKey { - type Item = <&'a SmallCidNonEmptyVec as IntoIterator>::Item; - - type IntoIter = <&'a SmallCidNonEmptyVec as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() - } -} - -impl IntoIterator for TipsetKey { - type Item = ::Item; - - type IntoIter = ::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - #[cfg(test)] impl Default for TipsetKey { fn default() -> Self { diff --git a/src/cid_collections/hash_set.rs b/src/cid_collections/hash_set.rs index a1e518b36c7..77bc8c33c74 100644 --- a/src/cid_collections/hash_set.rs +++ b/src/cid_collections/hash_set.rs @@ -10,7 +10,7 @@ use std::collections::HashSet; /// A hash set implemented as a `HashMap` where the value is `()`. /// /// See also [`HashSet`]. -#[derive(Default, Clone, Debug, PartialEq, Eq)] +#[derive(Default, Clone, Debug, PartialEq, Eq, derive_more::IntoIterator)] pub struct CidHashSet { inner: CidHashMap<()>, } @@ -73,31 +73,3 @@ impl FromIterator for CidHashSet { this } } - -pub struct IntoIter { - inner: hash_map::IntoIter<()>, -} - -impl Iterator for IntoIter { - type Item = Cid; - - fn next(&mut self) -> Option { - self.inner.next().map(|(it, ())| it) - } - - fn size_hint(&self) -> (usize, Option) { - self.inner.size_hint() - } -} - -impl IntoIterator for CidHashSet { - type Item = Cid; - - type IntoIter = IntoIter; - - fn into_iter(self) -> Self::IntoIter { - IntoIter { - inner: self.inner.into_iter(), - } - } -} From 8773c2c505172ea2b1106b7af2d648cd9b0443c7 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Mon, 26 Jan 2026 15:00:04 +0100 Subject: [PATCH 2/2] iter not needed at all --- src/cid_collections/hash_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cid_collections/hash_set.rs b/src/cid_collections/hash_set.rs index 77bc8c33c74..7195109f997 100644 --- a/src/cid_collections/hash_set.rs +++ b/src/cid_collections/hash_set.rs @@ -10,7 +10,7 @@ use std::collections::HashSet; /// A hash set implemented as a `HashMap` where the value is `()`. /// /// See also [`HashSet`]. -#[derive(Default, Clone, Debug, PartialEq, Eq, derive_more::IntoIterator)] +#[derive(Default, Clone, Debug, PartialEq, Eq)] pub struct CidHashSet { inner: CidHashMap<()>, }