Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl clone for iter/values/keys of storage types #1224

Merged
merged 7 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions near-sdk/src/store/free_list/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ where
}
}

impl<'a, T> Clone for Iter<'a, T>
g4titanx marked this conversation as resolved.
Show resolved Hide resolved
where
T: BorshDeserialize + BorshSerialize + Clone,
{
fn clone(&self) -> Self {
Self { values: self.values.clone(), elements_left: self.elements_left }
}
}

impl<'a, T> ExactSizeIterator for Iter<'a, T> where T: BorshSerialize + BorshDeserialize {}
impl<'a, T> FusedIterator for Iter<'a, T> where T: BorshSerialize + BorshDeserialize {}

Expand Down
11 changes: 11 additions & 0 deletions near-sdk/src/store/iterable_map/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ where
}
}

impl<'a, K, V, H> Clone for Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize + Clone,
V: BorshSerialize + BorshDeserialize,
H: ToKey,
{
fn clone(&self) -> Self {
Self { keys: self.keys.clone(), values: self.values }
}
}

impl<'a, K, V, H> ExactSizeIterator for Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize + Clone,
Expand Down
9 changes: 9 additions & 0 deletions near-sdk/src/store/iterable_set/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ where
}
}

impl<'a, T> Clone for Iter<'a, T>
where
T: BorshSerialize + Ord + BorshDeserialize,
{
fn clone(&self) -> Self {
Self { elements: self.elements.clone() }
}
}

impl<'a, T> ExactSizeIterator for Iter<'a, T> where T: BorshSerialize + Ord + BorshDeserialize {}
impl<'a, T> FusedIterator for Iter<'a, T> where T: BorshSerialize + Ord + BorshDeserialize {}

Expand Down
11 changes: 11 additions & 0 deletions near-sdk/src/store/tree_map/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ where
}
}

impl<'a, K, V, H> Clone for Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize + Clone,
V: BorshSerialize + BorshDeserialize,
H: ToKey,
{
fn clone(&self) -> Self {
Self { keys: self.keys.clone(), values: self.values }
}
}

impl<'a, K, V, H> ExactSizeIterator for Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize + Clone,
Expand Down
31 changes: 31 additions & 0 deletions near-sdk/src/store/unordered_map/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ where
}
}

impl<'a, K, V, H> Clone for Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize + Clone,
V: BorshSerialize + BorshDeserialize,
H: ToKey,
{
fn clone(&self) -> Self {
Self { keys: self.keys.clone(), values: self.values }
}
}

impl<'a, K, V, H> ExactSizeIterator for Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize + Clone,
Expand Down Expand Up @@ -262,6 +273,15 @@ where
}
}

impl<'a, K> Clone for Keys<'a, K>
where
K: BorshSerialize + BorshDeserialize + Clone,
{
fn clone(&self) -> Self {
Self { inner: self.inner.clone() }
}
}

impl<'a, K> ExactSizeIterator for Keys<'a, K> where K: BorshSerialize + BorshDeserialize {}
impl<'a, K> FusedIterator for Keys<'a, K> where K: BorshSerialize + BorshDeserialize {}

Expand Down Expand Up @@ -322,6 +342,17 @@ where
}
}

impl<'a, K, V, H> Clone for Values<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize + Clone,
V: BorshSerialize + BorshDeserialize + Clone,
H: ToKey,
{
fn clone(&self) -> Self {
Self { inner: self.inner.clone() }
}
}

impl<'a, K, V, H> ExactSizeIterator for Values<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize + Clone,
Expand Down
9 changes: 9 additions & 0 deletions near-sdk/src/store/unordered_set/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ where
}
}

impl<'a, T> Clone for Iter<'a, T>
where
T: BorshSerialize + Ord + BorshDeserialize + Clone,
{
fn clone(&self) -> Self {
Self { elements: self.elements.clone() }
}
}

impl<'a, T> ExactSizeIterator for Iter<'a, T> where T: BorshSerialize + Ord + BorshDeserialize {}
impl<'a, T> FusedIterator for Iter<'a, T> where T: BorshSerialize + Ord + BorshDeserialize {}

Expand Down
9 changes: 9 additions & 0 deletions near-sdk/src/store/vec/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ where
}
}

impl<'a, T> Clone for Iter<'a, T>
where
T: BorshSerialize + BorshDeserialize,
{
fn clone(&self) -> Self {
Self { vec: self.vec, range: self.range.clone() }
}
}

impl<'a, T> ExactSizeIterator for Iter<'a, T> where T: BorshSerialize + BorshDeserialize {}
impl<'a, T> FusedIterator for Iter<'a, T> where T: BorshSerialize + BorshDeserialize {}

Expand Down
Loading