Struct voladdress::VolAddress[][src]

#[repr(transparent)]pub struct VolAddress<T, R, W> { /* fields omitted */ }

A volatile address.

This type stores a memory address and provides ergonomic volatile access to said memory address.

Generic Parameters

  • T: The type of the value stored at the address.
    • The target type type must impl Copy for reading and writing to be allowed.
  • R: If the address is readable.
    • If R=Safe then you can safely read from the address.
    • If R=Unsafe then you can unsafely read from the address.
    • Otherwise you cannot read from the address.
  • W: If the address is writable.
    • If W=Safe then you can safely write to the address.
    • If W=Unsafe then you can unsafely write to the address.
    • Otherwise you cannot write to the address.

The VolAddress type is intended to represent a single value of a T type that is the size of a single machine register (or less).

  • If there’s an array of contiguous T values you want to model, consider using VolBlock instead.
  • If there’s a series of strided T values you want to model, consider using VolSeries instead.
  • If the T type is larger than a single machine register it’s probably not a good fit for the VolAddress abstraction.

Safety

This type’s safety follows the “unsafe creation, then safe use” strategy.

  • Validity Invariant: The address of a VolAddress must always be non-zero, or you will instantly trigger UB.
  • Safety Invariant: The address of a VolAddress must be an aligned and legal address for a T type value (with correct R and W permissions) within the device’s memory space, otherwise the read and write methods will trigger UB when called.

Implementations

impl<T, R, W> VolAddress<T, R, W>[src]

#[must_use]pub const unsafe fn new(address: usize) -> Self[src]

Constructs the value.

Safety

  • As per the type docs.

#[must_use]pub const unsafe fn cast<Z>(self) -> VolAddress<Z, R, W>[src]

Changes the target type from T to Z.

Safety

  • As per the type docs

#[must_use]pub const fn as_usize(self) -> usize[src]

Converts the VolAddress back into a normal usize value.

#[must_use]pub const unsafe fn add(self, count: usize) -> Self[src]

Advances the pointer by the given number of positions (usize).

Shorthand for addr.offset(count as isize)

This is intended to basically work like <*mut T>::wrapping_add.

Safety

  • As per the type docs

#[must_use]pub const unsafe fn sub(self, count: usize) -> Self[src]

Reverses the pointer by the given number of positions (usize).

Shorthand for addr.offset((count as isize).wrapping_neg())

This is intended to basically work like <*mut T>::wrapping_sub.

Safety

  • As per the type docs

#[must_use]pub const unsafe fn offset(self, count: isize) -> Self[src]

Offsets the address by the given number of positions (isize).

This is intended to basically work like <*mut T>::wrapping_offset.

Safety

  • As per the type docs

impl<T, W> VolAddress<T, Safe, W> where
    T: Copy
[src]

#[must_use]pub fn read(self) -> T[src]

Volatile reads the current value of A.

impl<T, W> VolAddress<T, Unsafe, W> where
    T: Copy
[src]

#[must_use]pub unsafe fn read(self) -> T[src]

Volatile reads the current value of A.

Safety

  • The safety rules of reading this address depend on the device. Consult your hardware manual.

impl<T, R> VolAddress<T, R, Safe> where
    T: Copy
[src]

pub fn write(self, t: T)[src]

Volatile writes a new value to A.

impl<T, R> VolAddress<T, R, Unsafe> where
    T: Copy
[src]

pub unsafe fn write(self, t: T)[src]

Volatile writes a new value to A.

Safety

  • The safety rules of reading this address depend on the device. Consult your hardware manual.

Trait Implementations

impl<T, R, W> Clone for VolAddress<T, R, W>[src]

impl<T, R, W> Copy for VolAddress<T, R, W>[src]

impl<T, R, W> Debug for VolAddress<T, R, W>[src]

impl<T: Eq, R: Eq, W: Eq> Eq for VolAddress<T, R, W>[src]

impl<T: Hash, R: Hash, W: Hash> Hash for VolAddress<T, R, W>[src]

impl<T: Ord, R: Ord, W: Ord> Ord for VolAddress<T, R, W>[src]

impl<T: PartialEq, R: PartialEq, W: PartialEq> PartialEq<VolAddress<T, R, W>> for VolAddress<T, R, W>[src]

impl<T: PartialOrd, R: PartialOrd, W: PartialOrd> PartialOrd<VolAddress<T, R, W>> for VolAddress<T, R, W>[src]

impl<T, R, W> StructuralEq for VolAddress<T, R, W>[src]

impl<T, R, W> StructuralPartialEq for VolAddress<T, R, W>[src]

Auto Trait Implementations

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.