Struct voladdress::VolRegion
source · #[repr(C)]pub struct VolRegion<T, R, W> { /* private fields */ }
Expand description
A dynamically sized span of volatile memory.
If you think of VolBlock as being similar to an array, this type is more similar to a slice.
The primary utility of this type is just that it bundles a pointer and
length together, which allows you to have safe dynamic bounds checking. Just
like with VolBlock
, It does not have a lifetime or participate in
borrow checking, and it does not enforce exclusive access.
A VolRegion
assumes that elements of the region are directly one after the
other (again, like how VolBlock
works). If you need dynamic bounds
checking on a spaced out series of values that would be some other type,
which doesn’t currently exist in the library. (Open a PR maybe?)
Generic Parameters
T
/R
/W
: These parameters are applied to theVolAddress
type returned when accessing the region in any way (indexing, iteration, etc).
Safety
- This type stores a base
VolAddress
internally, and so you must follow all of those safety rules. Notably, the base address must never be zero. - The region must legally contain
len
contiguous values of theT
type, starting from the base address. - The region must not wrap around past the end of the address space.
Implementations§
source§impl<T, R, W> VolRegion<T, R, W>
impl<T, R, W> VolRegion<T, R, W>
sourcepub const unsafe fn from_raw_parts(addr: VolAddress<T, R, W>, len: usize) -> Self
pub const unsafe fn from_raw_parts(addr: VolAddress<T, R, W>, len: usize) -> Self
sourcepub const fn as_usize(self) -> usize
pub const fn as_usize(self) -> usize
Converts the VolBlock
the usize
for the start of the block.
sourcepub const fn as_ptr(self) -> *const T
pub const fn as_ptr(self) -> *const T
Converts the VolBlock
into an individual const pointer.
This should usually only be used when you need to call a foreign function that expects a pointer.
sourcepub const fn as_mut_ptr(self) -> *mut T
pub const fn as_mut_ptr(self) -> *mut T
Converts the VolBlock
into an individual mut pointer.
This should usually only be used when you need to call a foreign function that expects a pointer.
sourcepub fn as_slice_ptr(self) -> *const [T]
pub fn as_slice_ptr(self) -> *const [T]
Converts the VolBlock
into a const slice pointer.
sourcepub fn as_slice_mut_ptr(self) -> *mut [T]
pub fn as_slice_mut_ptr(self) -> *mut [T]
Converts the VolBlock
into an mut slice pointer.
sourcepub const fn index(self, i: usize) -> VolAddress<T, R, W>
pub const fn index(self, i: usize) -> VolAddress<T, R, W>
sourcepub const fn get(self, i: usize) -> Option<VolAddress<T, R, W>>
pub const fn get(self, i: usize) -> Option<VolAddress<T, R, W>>
Gets Some(addr)
if in bounds, or None
if out of bounds.
sourcepub fn sub_slice<RB: RangeBounds<usize>>(self, r: RB) -> Self
pub fn sub_slice<RB: RangeBounds<usize>>(self, r: RB) -> Self
Gets a sub-slice of this region as a new region.
Panics
- If either specified end of the range is out of bounds this will panic.
sourcepub const fn iter(self) -> VolBlockIter<T, R, W> ⓘ
pub const fn iter(self) -> VolBlockIter<T, R, W> ⓘ
Gives an iterator over this region.
sourcepub fn iter_range<RB: RangeBounds<usize>>(self, r: RB) -> VolBlockIter<T, R, W> ⓘ
pub fn iter_range<RB: RangeBounds<usize>>(self, r: RB) -> VolBlockIter<T, R, W> ⓘ
Same as region.sub_slice(range).iter()
source§impl<T, W> VolRegion<T, Safe, W>where
T: Copy,
impl<T, W> VolRegion<T, Safe, W>where T: Copy,
sourcepub fn read_to_slice(self, buffer: &mut [T])
pub fn read_to_slice(self, buffer: &mut [T])
Volatile reads each element into the provided buffer.
Panics
- If the buffer’s length is not exactly this region’s length.
source§impl<T, W> VolRegion<T, Unsafe, W>where
T: Copy,
impl<T, W> VolRegion<T, Unsafe, W>where T: Copy,
sourcepub unsafe fn read_to_slice(self, buffer: &mut [T])
pub unsafe fn read_to_slice(self, buffer: &mut [T])
source§impl<T, R> VolRegion<T, R, Safe>where
T: Copy,
impl<T, R> VolRegion<T, R, Safe>where T: Copy,
sourcepub fn write_from_slice(self, buffer: &[T])
pub fn write_from_slice(self, buffer: &[T])
Volatile all slice elements into this region.
Panics
- If the buffer’s length is not exactly this region’s length.
Trait Implementations§
source§impl<T: Ord, R: Ord, W: Ord> Ord for VolRegion<T, R, W>
impl<T: Ord, R: Ord, W: Ord> Ord for VolRegion<T, R, W>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<T: PartialEq, R: PartialEq, W: PartialEq> PartialEq<VolRegion<T, R, W>> for VolRegion<T, R, W>
impl<T: PartialEq, R: PartialEq, W: PartialEq> PartialEq<VolRegion<T, R, W>> for VolRegion<T, R, W>
source§impl<T: PartialOrd, R: PartialOrd, W: PartialOrd> PartialOrd<VolRegion<T, R, W>> for VolRegion<T, R, W>
impl<T: PartialOrd, R: PartialOrd, W: PartialOrd> PartialOrd<VolRegion<T, R, W>> for VolRegion<T, R, W>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more