Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions src/curr/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,23 @@ impl<'a, T, const MAX: u32> core::iter::IntoIterator for &'a mut VecM<T, MAX> {
}
}

#[cfg(feature = "alloc")]
impl<T, const MAX: u32> core::iter::IntoIterator for VecM<T, MAX> {
type Item = T;
type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

impl<'a, T, const MAX: u32> core::iter::IntoIterator for &'a VecM<T, MAX> {
type Item = &'a T;
type IntoIter = core::slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

impl<T: Clone, const MAX: u32> VecM<T, MAX> {
#[must_use]
#[cfg(feature = "alloc")]
Expand Down
17 changes: 17 additions & 0 deletions src/next/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,23 @@ impl<'a, T, const MAX: u32> core::iter::IntoIterator for &'a mut VecM<T, MAX> {
}
}

#[cfg(feature = "alloc")]
impl<T, const MAX: u32> core::iter::IntoIterator for VecM<T, MAX> {
type Item = T;
type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

impl<'a, T, const MAX: u32> core::iter::IntoIterator for &'a VecM<T, MAX> {
type Item = &'a T;
type IntoIter = core::slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

impl<T: Clone, const MAX: u32> VecM<T, MAX> {
#[must_use]
#[cfg(feature = "alloc")]
Expand Down
26 changes: 25 additions & 1 deletion tests/vecm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use stellar_xdr::curr as stellar_xdr;
#[cfg(feature = "next")]
use stellar_xdr::next as stellar_xdr;

use stellar_xdr::{BytesM, Limits, ReadXdr, ScVal};
use stellar_xdr::{BytesM, Limits, ReadXdr, ScVal, VecM};

#[test]
fn valid_len() {
Expand Down Expand Up @@ -76,3 +76,27 @@ fn invalid_bytes_len() {
let result: Result<BytesM, _> = BytesM::from_xdr(data, Limits::none());
assert!(result.is_err());
}

#[test]
fn into_iter_owned() {
let v: VecM<u32, 5> = VecM::try_from(vec![1u32, 2, 3]).unwrap();
let collected: Vec<u32> = v.into_iter().collect();
assert_eq!(collected, vec![1, 2, 3]);
}

#[test]
fn into_iter_ref() {
let v: VecM<u32, 5> = VecM::try_from(vec![1u32, 2, 3]).unwrap();
let collected: Vec<&u32> = (&v).into_iter().collect();
assert_eq!(collected, vec![&1, &2, &3]);
}

#[test]
fn into_iter_for_loop() {
let v: VecM<u32, 5> = VecM::try_from(vec![10u32, 20, 30]).unwrap();
let mut sum = 0;
for item in v {
sum += item;
}
assert_eq!(sum, 60);
}
17 changes: 17 additions & 0 deletions xdr-generator/generator/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,23 @@ impl<'a, T, const MAX: u32> core::iter::IntoIterator for &'a mut VecM<T, MAX> {
}
}

#[cfg(feature = "alloc")]
impl<T, const MAX: u32> core::iter::IntoIterator for VecM<T, MAX> {
type Item = T;
type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

impl<'a, T, const MAX: u32> core::iter::IntoIterator for &'a VecM<T, MAX> {
type Item = &'a T;
type IntoIter = core::slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

impl<T: Clone, const MAX: u32> VecM<T, MAX> {
#[must_use]
#[cfg(feature = "alloc")]
Expand Down
Loading