[][src]Struct vm_memory::volatile_memory::VolatileArrayRef

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

A memory location that supports volatile access to an array of elements of type 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> VolatileArrayRef<'a, T>[src]

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

Creates a VolatileArrayRef to an array of elements of type T.

Safety

To use this safely, the caller must guarantee that the memory at addr is big enough for nelem values of type 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 is_empty(&self) -> bool[src]

Returns true if this array is empty.

Examples

  let v_array = unsafe { VolatileArrayRef::<u32>::new(0 as *mut _, 0) };
  assert!(v_array.is_empty());

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

Returns the number of elements in the array.

Examples

  let v_array = unsafe { VolatileArrayRef::<u32>::new(0 as *mut _, 1) };
  assert_eq!(v_array.len(), 1);

pub fn element_size(&self) -> usize[src]

Returns the size of T.

Examples

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

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

Returns a pointer to the underlying memory.

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

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

pub fn ref_at(&self, index: usize) -> VolatileRef<'a, T>[src]

Does a volatile read of the element at index.

pub fn load(&self, index: usize) -> T[src]

Does a volatile read of the element at index.

pub fn store(&self, index: usize, value: T)[src]

Does a volatile write of the element at index.

pub fn copy_to(&self, buf: &mut [T]) -> usize[src]

Copies as many elements of type T as possible from this array to buf.

Copies self.len() or buf.len() times the size of T bytes, whichever is smaller, to buf. The copy happens from smallest to largest address in T sized chunks using volatile reads.

Examples

let mut mem = [0u8; 32];
let mem_ref = &mut mem[..];
let vslice = mem_ref.get_slice(0, 32).map_err(|_| ())?;
let mut buf = [5u8; 16];
vslice.copy_to(&mut buf[..]);
for v in &buf[..] {
    assert_eq!(buf[0], 0);
}

pub fn copy_to_volatile_slice(&self, slice: VolatileSlice)[src]

Copies as many bytes as possible from this slice to the provided slice.

The copies happen in an undefined order.

Examples

let mut mem = [0u8; 32];
let mem_ref = &mut mem[..];
let vslice = mem_ref.get_slice(0, 32).map_err(|_| ())?;
vslice.copy_to_volatile_slice(vslice.get_slice(16, 16).map_err(|_| ())?);

pub fn copy_from(&self, buf: &[T])[src]

Copies as many elements of type T as possible from buf to this slice.

Copies self.len() or buf.len() times the size of T bytes, whichever is smaller, to this slice's memory. The copy happens from smallest to largest address in T sized chunks using volatile writes.

Examples

let mut mem = [0u8; 32];
let mem_ref = &mut mem[..];
let vslice = mem_ref.get_slice(0, 32).map_err(|_| ())?;
let buf = [5u8; 64];
vslice.copy_from(&buf[..]);
for i in 0..4 {
    assert_eq!(vslice.get_ref::<u32>(i * 4).map_err(|_| ())?.load(), 0x05050505);
}

Trait Implementations

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

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

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

impl<'a> From<VolatileSlice<'a>> for VolatileArrayRef<'a, u8>[src]

Auto Trait Implementations

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

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

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

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

impl<'a, T> UnwindSafe for VolatileArrayRef<'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.