Skip to content

Commit

Permalink
ManagedVecItem - ref for tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Nov 29, 2024
1 parent 490a31c commit 809b71a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions contracts/feature-tests/basic-features/src/echo_managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ pub trait EchoManagedTypes {
MultiValue3<ManagedAddress, usize, MultiValueEncodedCounted<MultiValue2<usize, usize>>>,
> {
let mut result = MultiValueEncoded::new();
for triple in address_number_pairs.into_iter() {
for triple in address_number_pairs {
let (address, x, counted_list) = triple.into_tuple();
let mut counted_lazy = MultiValueEncodedCounted::new();
let v = counted_list.into_vec();
for pair in &v {
for pair in v {
counted_lazy.push(pair);
}
result.push((address, x, counted_lazy).into());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
DecodeErrorHandler, EncodeErrorHandler, TopDecodeMulti, TopDecodeMultiInput,
TopEncodeMulti, TopEncodeMultiOutput, Vec,
},
types::ManagedType,
types::{ManagedType, ManagedVecOwnedIterator},
};

use crate::types::{ManagedVec, ManagedVecItem, ManagedVecRefIterator};
Expand Down Expand Up @@ -144,6 +144,20 @@ where
}
}

impl<M, T> IntoIterator for MultiValueManagedVec<M, T>
where
M: ManagedTypeApi,
T: ManagedVecItem,
{
type Item = T;

type IntoIter = ManagedVecOwnedIterator<M, T>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

impl<'a, M, T> IntoIterator for &'a MultiValueManagedVec<M, T>
where
M: ManagedTypeApi,
Expand Down
10 changes: 4 additions & 6 deletions framework/base/src/types/managed/wrapped/managed_vec_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ where
{
type PAYLOAD = <(T1, (T2, ())) as ManagedVecItemNestedTuple>::PAYLOAD;
const SKIPS_RESERIALIZATION: bool = T1::SKIPS_RESERIALIZATION && T2::SKIPS_RESERIALIZATION;
type Ref<'a> = Self;
type Ref<'a> = ManagedVecRef<'a, Self>;

fn read_from_payload(payload: &Self::PAYLOAD) -> Self {
let mut index = 0;
Expand All @@ -338,8 +338,7 @@ where
}

unsafe fn borrow_from_payload<'a>(payload: &Self::PAYLOAD) -> Self::Ref<'a> {
// TODO: tuple of refs
Self::read_from_payload(payload)
ManagedVecRef::new(Self::read_from_payload(payload))
}

fn save_to_payload(self, payload: &mut Self::PAYLOAD) {
Expand All @@ -362,7 +361,7 @@ where
{
type PAYLOAD = <(T1, (T2, (T3, ()))) as ManagedVecItemNestedTuple>::PAYLOAD;
const SKIPS_RESERIALIZATION: bool = T1::SKIPS_RESERIALIZATION && T2::SKIPS_RESERIALIZATION;
type Ref<'a> = Self;
type Ref<'a> = ManagedVecRef<'a, Self>;

fn read_from_payload(payload: &Self::PAYLOAD) -> Self {
let mut index = 0;
Expand All @@ -377,8 +376,7 @@ where
}

unsafe fn borrow_from_payload<'a>(payload: &Self::PAYLOAD) -> Self::Ref<'a> {
// TODO: tuple of refs
Self::read_from_payload(payload)
ManagedVecRef::new(Self::read_from_payload(payload))
}

fn save_to_payload(self, payload: &mut Self::PAYLOAD) {
Expand Down

0 comments on commit 809b71a

Please sign in to comment.