Struct voladdress::VolAddress[][src]

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

A volatile address.

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

Note that this type has several methods for accessing the data at the address specified, and a particular instance of this type can use them unsafely, use them safely, or not use them at all based on the generic values of R and W (explained below).

  • read
  • write
  • apply (reads, runs a function, then writes)

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.
  • Synchronization Invariant: Volatile access has no cross-thread synchronization behavior within the LLVM memory model. The results of all volatile access is target-dependent, including cross-thread access. Volatile access has no automatic synchronization of its own, and so if your target requires some sort of synchronization for volatile accesses of the address in question you must provide the appropriate synchronization in some way external to this type.

Implementations

Constructs the value.

Safety

  • As per the type docs.

Changes the target type from T to Z.

Safety

  • As per the type docs

Converts the VolAddress back into a normal usize value.

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

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

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

Volatile reads the current value of A.

Volatile reads the current value of A.

Safety

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

Volatile writes a new value to A.

Volatile writes a new value to A.

Safety

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

Reads the address, applies the operation, and writes back the new value.

Reads the address, applies the operation, and writes back the new value.

Safety

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

Reads the address, applies the operation, and writes back the new value.

Safety

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

Reads the address, applies the operation, and writes back the new value.

Safety

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

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

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.