Skip to content
Snippets Groups Projects
Commit 0e3918d9 authored by Keith Yeung's avatar Keith Yeung Committed by GitHub
Browse files

Implement more IntoIter traits for bounded types (#11616)

parent 7b712fa4
No related merge requests found
......@@ -252,6 +252,24 @@ impl<K, V, S> IntoIterator for BoundedBTreeMap<K, V, S> {
}
}
impl<'a, K, V, S> IntoIterator for &'a BoundedBTreeMap<K, V, S> {
type Item = (&'a K, &'a V);
type IntoIter = sp_std::collections::btree_map::Iter<'a, K, V>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<'a, K, V, S> IntoIterator for &'a mut BoundedBTreeMap<K, V, S> {
type Item = (&'a K, &'a mut V);
type IntoIter = sp_std::collections::btree_map::IterMut<'a, K, V>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut()
}
}
impl<K, V, S> MaxEncodedLen for BoundedBTreeMap<K, V, S>
where
K: MaxEncodedLen,
......
......@@ -230,6 +230,15 @@ impl<T, S> IntoIterator for BoundedBTreeSet<T, S> {
}
}
impl<'a, T, S> IntoIterator for &'a BoundedBTreeSet<T, S> {
type Item = &'a T;
type IntoIter = sp_std::collections::btree_set::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<T, S> MaxEncodedLen for BoundedBTreeSet<T, S>
where
T: MaxEncodedLen,
......
......@@ -149,6 +149,14 @@ impl<'a, T, S> From<BoundedSlice<'a, T, S>> for &'a [T] {
}
}
impl<'a, T, S> sp_std::iter::IntoIterator for BoundedSlice<'a, T, S> {
type Item = &'a T;
type IntoIter = sp_std::slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<T: Decode, S: Get<u32>> Decode for BoundedVec<T, S> {
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
let inner = Vec::<T>::decode(input)?;
......@@ -605,6 +613,22 @@ impl<T, S> sp_std::iter::IntoIterator for BoundedVec<T, S> {
}
}
impl<'a, T, S> sp_std::iter::IntoIterator for &'a BoundedVec<T, S> {
type Item = &'a T;
type IntoIter = sp_std::slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<'a, T, S> sp_std::iter::IntoIterator for &'a mut BoundedVec<T, S> {
type Item = &'a mut T;
type IntoIter = sp_std::slice::IterMut<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut()
}
}
impl<T, S> codec::DecodeLength for BoundedVec<T, S> {
fn len(self_encoded: &[u8]) -> Result<usize, codec::Error> {
// `BoundedVec<T, _>` stored just a `Vec<T>`, thus the length is at the beginning in
......
......@@ -262,6 +262,22 @@ impl<T, S> sp_std::iter::IntoIterator for WeakBoundedVec<T, S> {
}
}
impl<'a, T, S> sp_std::iter::IntoIterator for &'a WeakBoundedVec<T, S> {
type Item = &'a T;
type IntoIter = sp_std::slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<'a, T, S> sp_std::iter::IntoIterator for &'a mut WeakBoundedVec<T, S> {
type Item = &'a mut T;
type IntoIter = sp_std::slice::IterMut<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut()
}
}
impl<T, S> codec::DecodeLength for WeakBoundedVec<T, S> {
fn len(self_encoded: &[u8]) -> Result<usize, codec::Error> {
// `WeakBoundedVec<T, _>` stored just a `Vec<T>`, thus the length is at the beginning in
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment