[−][src]Struct vm_memory::volatile_memory::VolatileArrayRef
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]
T: 'a,
fn clone(&self) -> VolatileArrayRef<'a, T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a, T: Copy + ByteValued> Copy for VolatileArrayRef<'a, T> where
T: 'a,
[src]
T: 'a,
impl<'a, T: Debug + ByteValued> Debug for VolatileArrayRef<'a, T> where
T: 'a,
[src]
T: 'a,
impl<'a> From<VolatileSlice<'a>> for VolatileArrayRef<'a, u8>
[src]
fn from(slice: VolatileSlice<'a>) -> Self
[src]
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for VolatileArrayRef<'a, T> where
T: RefUnwindSafe,
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,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,