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..7195109f997 100644 --- a/src/cid_collections/hash_set.rs +++ b/src/cid_collections/hash_set.rs @@ -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(), - } - } -}