From a045b27656fd9dacefa79bff214b3795bee0bf2f Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 19 Nov 2024 19:35:28 +0100 Subject: [PATCH] merkle: update MerkleLeaves trait with removing lifetime and associated iterator type Signed-off-by: Dr Maxim Orlovsky --- commit_verify/src/merkle.rs | 57 +++++++++---------------------------- 1 file changed, 14 insertions(+), 43 deletions(-) diff --git a/commit_verify/src/merkle.rs b/commit_verify/src/merkle.rs index 3e03fe52..bede75b9 100644 --- a/commit_verify/src/merkle.rs +++ b/commit_verify/src/merkle.rs @@ -19,8 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::{iter, slice}; -use std::collections::{btree_set, BTreeSet}; +use std::collections::BTreeSet; use std::ops::SubAssign; use amplify::confinement::Confined; @@ -202,77 +201,49 @@ impl MerkleHash { pub trait MerkleLeaves { type Leaf: CommitId; - // TODO: Remove associated type - type LeafIter<'tmp>: ExactSizeIterator - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_>; + fn merkle_leaves(&self) -> impl ExactSizeIterator; } impl MerkleLeaves for Confined, MIN, { u8::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u8::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u16::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u16::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u32::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u32::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } /// Helper struct to track depth when working with Merkle blocks.