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>
impl<'a, T: DataInit> VolatileRef<'a, T>
Sourcepub unsafe fn new(addr: *mut T) -> VolatileRef<'a, T>
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.
Sourcepub fn as_mut_ptr(&self) -> *mut T
pub fn as_mut_ptr(&self) -> *mut T
Gets the address of this slice’s memory.
Sourcepub fn size(&self) -> usize
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>());Sourcepub fn to_slice(&self) -> VolatileSlice<'a>
pub fn to_slice(&self) -> VolatileSlice<'a>
Converts this T reference to a raw slice with the same size and address.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more