[][src]Struct vm_memory::volatile_memory::VolatileRef

pub struct VolatileRef<'a, T: ByteValued> where
    T: 'a, 
{ /* fields omitted */ }

A memory location that supports volatile access to an instance of T.

Examples

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

Implementations

impl<'a, T: ByteValued> VolatileRef<'a, T>[src]

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

Creates a VolatileRef to an instance of T.

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.

pub fn as_ptr(self) -> *mut u8[src]

Returns a pointer to the underlying memory.

pub fn len(self) -> usize[src]

Gets the size of the referenced type T.

Examples

  let v_ref = unsafe { VolatileRef::<u32>::new(0 as *mut _) };
  assert_eq!(v_ref.len(), size_of::<u32>() as usize);

pub fn store(self, v: T)[src]

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

pub fn load(self) -> T[src]

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

pub fn to_slice(self) -> VolatileSlice<'a>[src]

Converts this to a VolatileSlice with the same size and address.

Trait Implementations

impl<'a, T: Clone + ByteValued> Clone for VolatileRef<'a, T> where
    T: 'a, 
[src]

impl<'a, T: Copy + ByteValued> Copy for VolatileRef<'a, T> where
    T: 'a, 
[src]

impl<'a, T: Debug + ByteValued> Debug for VolatileRef<'a, T> where
    T: 'a, 
[src]

Auto Trait Implementations

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

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.