Skip to content

Commit

Permalink
impl clone for iter/values/keys of storage types
Browse files Browse the repository at this point in the history
  • Loading branch information
g4titanx committed Jul 31, 2024
1 parent 0f46b0d commit df0703a
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
12 changes: 12 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,18 @@ where
}
}

impl<'a, T> Clone for Iter<'a, T>
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
14 changes: 14 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,20 @@ 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
11 changes: 11 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,17 @@ 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
14 changes: 14 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,20 @@ 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
38 changes: 38 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,20 @@ 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 +276,17 @@ 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 +347,19 @@ 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
11 changes: 11 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,17 @@ 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
12 changes: 12 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,18 @@ 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

0 comments on commit df0703a

Please sign in to comment.