Implement more IntoIter traits for bounded types (#11616)

This commit is contained in:
Keith Yeung
2022-06-07 15:32:30 +01:00
committed by GitHub
parent 7b712fa4ff
commit 0e3918d9fe
4 changed files with 67 additions and 0 deletions
@@ -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