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 the VolAddress 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 the T 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>

source

pub const unsafe fn from_raw_parts(addr: VolAddress<T, R, W>, len: usize) -> Self

Constructs a region from raw parts.

Safety
  • As per the type docs.
source

pub const fn len(self) -> usize

Gets the length (in elements) of the region.

source

pub const fn as_usize(self) -> usize

Converts the VolBlock the usize for the start of the block.

source

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.

source

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.

source

pub fn as_slice_ptr(self) -> *const [T]

Converts the VolBlock into a const slice pointer.

source

pub fn as_slice_mut_ptr(self) -> *mut [T]

Converts the VolBlock into an mut slice pointer.

source

pub const fn index(self, i: usize) -> VolAddress<T, R, W>

Index into the region.

Panics
  • If the index requested is out of bounds this will panic.
source

pub const fn get(self, i: usize) -> Option<VolAddress<T, R, W>>

Gets Some(addr) if in bounds, or None if out of bounds.

source

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.
source

pub const fn iter(self) -> VolBlockIter<T, R, W>

Gives an iterator over this region.

source

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,

source

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,

source

pub unsafe 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.
Safety
  • The safety rules of reading this address depend on the device. Consult your hardware manual.
source§

impl<T, R> VolRegion<T, R, Safe>where T: Copy,

source

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.
source§

impl<T, R> VolRegion<T, R, Unsafe>where T: Copy,

source

pub unsafe 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.
Safety
  • The safety rules of writing this address depend on the device. Consult your hardware manual.

Trait Implementations§

source§

impl<T, R, W> Clone for VolRegion<T, R, W>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, R, W> Debug for VolRegion<T, R, W>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T, R, W, const C: usize> From<VolBlock<T, R, W, C>> for VolRegion<T, R, W>

source§

fn from(block: VolBlock<T, R, W, C>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash, R: Hash, W: Hash> Hash for VolRegion<T, R, W>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: Ord, R: Ord, W: Ord> Ord for VolRegion<T, R, W>

source§

fn cmp(&self, other: &VolRegion<T, R, W>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq, R: PartialEq, W: PartialEq> PartialEq<VolRegion<T, R, W>> for VolRegion<T, R, W>

source§

fn eq(&self, other: &VolRegion<T, R, W>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd, R: PartialOrd, W: PartialOrd> PartialOrd<VolRegion<T, R, W>> for VolRegion<T, R, W>

source§

fn partial_cmp(&self, other: &VolRegion<T, R, W>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, R, W> Copy for VolRegion<T, R, W>

source§

impl<T: Eq, R: Eq, W: Eq> Eq for VolRegion<T, R, W>

source§

impl<T, R, W> StructuralEq for VolRegion<T, R, W>

source§

impl<T, R, W> StructuralPartialEq for VolRegion<T, R, W>

Auto Trait Implementations§

§

impl<T, R, W> RefUnwindSafe for VolRegion<T, R, W>where R: RefUnwindSafe, T: RefUnwindSafe, W: RefUnwindSafe,

§

impl<T, R, W> Send for VolRegion<T, R, W>where R: Send, T: Send, W: Send,

§

impl<T, R, W> Sync for VolRegion<T, R, W>where R: Sync, T: Sync, W: Sync,

§

impl<T, R, W> Unpin for VolRegion<T, R, W>where R: Unpin, T: Unpin, W: Unpin,

§

impl<T, R, W> UnwindSafe for VolRegion<T, R, W>where R: UnwindSafe, T: UnwindSafe, W: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.