Add iter() to owned slice (#1620)

This commit is contained in:
Andrea Fioraldi 2023-10-11 14:13:26 +02:00 committed by GitHub
parent 47cd4dfea6
commit 6986317a03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -286,6 +286,11 @@ impl<'a, T> OwnedSlice<'a, T> {
}
}
}
/// Returns an iterator over the slice.
pub fn iter(&self) -> Iter<'_, T> {
<&Self as IntoIterator>::into_iter(self)
}
}
impl<'a, 'it, T> IntoIterator for &'it OwnedSlice<'a, T> {
@ -509,6 +514,16 @@ impl<'a, T: 'a + Sized> OwnedMutSlice<'a, T> {
}
}
}
/// Returns an iterator over the slice.
pub fn iter(&self) -> Iter<'_, T> {
<&Self as IntoIterator>::into_iter(self)
}
/// Returns a mutable iterator over the slice.
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
<&mut Self as IntoIterator>::into_iter(self)
}
}
impl<'a, T: Sized> AsSlice for OwnedMutSlice<'a, T> {