Skip to content

Commit c62fa4b

Browse files
committed
add VolatilePtr::iter & VolatilePtr::iter_mut
1 parent 34a36a2 commit c62fa4b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,30 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
479479
}
480480
}
481481

482+
/// Returns an iterator over the slice.
483+
pub fn iter<'b>(
484+
self,
485+
) -> impl Iterator<Item = VolatilePtr<'a, T, Access<R, access::NoAccess>>> + 'b
486+
where
487+
'a: 'b,
488+
R: 'b,
489+
W: 'b,
490+
{
491+
let len = self.len();
492+
(0..len).map(move |i| self.index(i))
493+
}
494+
495+
/// Returns an iterator that allows modifying each value.
496+
pub fn iter_mut<'b>(self) -> impl Iterator<Item = VolatilePtr<'a, T, Access<R, W>>> + 'b
497+
where
498+
'a: 'b,
499+
R: 'b,
500+
W: 'b,
501+
{
502+
let len = self.len();
503+
(0..len).map(move |i| self.index_mut(i))
504+
}
505+
482506
/// Copies all elements from `self` into `dst`, using a volatile memcpy.
483507
///
484508
/// The length of `dst` must be the same as `self`.

0 commit comments

Comments
 (0)