VolatileRef

Struct VolatileRef 

Source
pub struct VolatileRef<'a, T>
where T: 'a + DataInit,
{ /* private fields */ }
Expand description

A memory location that supports volatile access of a T.

§Examples

  let mut v = 5u32;
  assert_eq!(v, 5);
  let v_ref = unsafe { VolatileRef::new(&mut v as *mut u32) };
  assert_eq!(v_ref.load(), 5);
  v_ref.store(500);
  assert_eq!(v, 500);

Implementations§

Source§

impl<'a, T: DataInit> VolatileRef<'a, T>

Source

pub unsafe fn new(addr: *mut T) -> VolatileRef<'a, T>

Creates a reference to raw memory that must support volatile access of T sized chunks.

§Safety

To use this safely, the caller must guarantee that the memory at addr is big enough for a T and is available for the duration of the lifetime of the new VolatileRef. The caller must also guarantee that all other users of the given chunk of memory are using volatile accesses.

Source

pub fn as_mut_ptr(&self) -> *mut T

Gets the address of this slice’s memory.

Source

pub fn size(&self) -> usize

Gets the size of this slice.

§Examples
  let v_ref = unsafe { VolatileRef::new(0 as *mut u32) };
  assert_eq!(v_ref.size(), size_of::<u32>());
Source

pub fn store(&self, v: T)

Does a volatile write of the value v to the address of this ref.

Source

pub fn load(&self) -> T

Does a volatile read of the value at the address of this ref.

Source

pub fn to_slice(&self) -> VolatileSlice<'a>

Converts this T reference to a raw slice with the same size and address.

Trait Implementations§

Source§

impl<'a, T> Debug for VolatileRef<'a, T>
where T: 'a + Debug + DataInit,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for VolatileRef<'a, T>

§

impl<'a, T> RefUnwindSafe for VolatileRef<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for VolatileRef<'a, T>

§

impl<'a, T> !Sync for VolatileRef<'a, T>

§

impl<'a, T> Unpin for VolatileRef<'a, T>

§

impl<'a, T> UnwindSafe for VolatileRef<'a, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.