[−][src]Struct vm_memory::volatile_memory::VolatileRef
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]
T: 'a,
fn clone(&self) -> VolatileRef<'a, T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a, T: Copy + ByteValued> Copy for VolatileRef<'a, T> where
T: 'a,
[src]
T: 'a,
impl<'a, T: Debug + ByteValued> Debug for VolatileRef<'a, T> where
T: 'a,
[src]
T: 'a,
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for VolatileRef<'a, T> where
T: RefUnwindSafe,
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,
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>,