Struct voladdress::VolBlock

source ·
#[repr(transparent)]
pub struct VolBlock<T, R, W, const C: usize> { /* private fields */ }
Expand description

A volatile memory block.

This is intended to model when a portion of memory is an array of identical values in a row, such as a block of 256 u16 values in a row.

Generic Parameters

  • T / R / W: These parameters are applied to the VolAddress type returned when accessing the block in any way (indexing, iteration, etc).
  • C: the count of elements in the block.

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 address space must legally contain C contiguous values of the T type, starting from the base address.
  • The memory block must not wrap around past the end of the address space.

Implementations§

source§

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

source

pub const unsafe fn new(base: usize) -> Self

Constructs the value.

Safety
  • As per the type docs.
source

pub const fn len(self) -> usize

The length of this block (in elements).

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 a mut slice pointer.

source

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

Indexes to the ith position of the memory block.

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

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

Gets the address of the ith position, if it’s in bounds.

source

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

Creates an iterator over the addresses of the memory block.

source

pub fn iter_range<RB: RangeBounds<usize>>(self, r: RB) -> VolBlockIter<T, R, W>

Makes an iterator over the range bounds given.

If the range given is empty then your iterator will be empty.

Panics
  • If the start or end of the range are out of bounds for the block.
source

pub const fn as_region(self) -> VolRegion<T, R, W>

View the volatile block as an equivalent spanned region.

This method exists because unfortunately the typing of the Deref trait doesn’t allow for a Block to deref into a Region, so we have to provide the conversion through this manual method.

Trait Implementations§

source§

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

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, const C: usize> Debug for VolBlock<T, R, W, C>

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, const C: usize> Hash for VolBlock<T, R, W, C>

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, const C: usize> Ord for VolBlock<T, R, W, C>

source§

fn cmp(&self, other: &VolBlock<T, R, W, C>) -> 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, const C: usize> PartialEq<VolBlock<T, R, W, C>> for VolBlock<T, R, W, C>

source§

fn eq(&self, other: &VolBlock<T, R, W, C>) -> 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, const C: usize> PartialOrd<VolBlock<T, R, W, C>> for VolBlock<T, R, W, C>

source§

fn partial_cmp(&self, other: &VolBlock<T, R, W, C>) -> 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, const C: usize> Pointer for VolBlock<T, R, W, C>

source§

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

Formats the value using the given formatter.
source§

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

source§

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

source§

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

source§

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

Auto Trait Implementations§

§

impl<T, R, W, const C: usize> RefUnwindSafe for VolBlock<T, R, W, C>where R: RefUnwindSafe, T: RefUnwindSafe, W: RefUnwindSafe,

§

impl<T, R, W, const C: usize> Send for VolBlock<T, R, W, C>where R: Send, T: Send, W: Send,

§

impl<T, R, W, const C: usize> Sync for VolBlock<T, R, W, C>where R: Sync, T: Sync, W: Sync,

§

impl<T, R, W, const C: usize> Unpin for VolBlock<T, R, W, C>where R: Unpin, T: Unpin, W: Unpin,

§

impl<T, R, W, const C: usize> UnwindSafe for VolBlock<T, R, W, C>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.