pub struct VolatileArrayRef<'a, T, B = ()> { /* private fields */ }
Expand description

A memory location that supports volatile access to an array of elements of type T.

§Examples

let mut v = [5u32; 1];
let v_ref = unsafe { VolatileArrayRef::new(&mut v[0] as *mut u32 as *mut u8, v.len()) };

assert_eq!(v[0], 5);
assert_eq!(v_ref.load(0), 5);
v_ref.store(0, 500);
assert_eq!(v[0], 500);

Implementations§

source§

impl<'a, T> VolatileArrayRef<'a, T>
where T: ByteValued,

source

pub unsafe fn new(addr: *mut u8, nelem: usize) -> Self

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.

source§

impl<'a, T, B> VolatileArrayRef<'a, T, B>
where T: ByteValued, B: BitmapSlice,

source

pub unsafe fn with_bitmap( addr: *mut u8, nelem: usize, bitmap: B, mmap: Option<&'a MmapInfo> ) -> Self

Creates a VolatileArrayRef to an array of elements of type T, using the provided bitmap object for dirty page tracking.

§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.

source

pub fn is_empty(&self) -> bool

Returns true if this array is empty.

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

pub fn len(&self) -> usize

Returns the number of elements in the array.

§Examples
assert_eq!(v_array.len(), 1);
source

pub fn element_size(&self) -> usize

Returns the size of T.

§Examples
let v_ref = unsafe { VolatileArrayRef::<u32>::new(0 as *mut _, 0) };
assert_eq!(v_ref.element_size(), size_of::<u32>() as usize);
source

pub fn ptr_guard(&self) -> PtrGuard

Returns a guard for the pointer to the underlying memory.

source

pub fn ptr_guard_mut(&self) -> PtrGuardMut

Returns a mutable guard for the pointer to the underlying memory.

source

pub fn bitmap(&self) -> &B

Borrows the inner BitmapSlice.

source

pub fn to_slice(&self) -> VolatileSlice<'a, B>

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

source

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

Does a volatile read of the element at index.

§Panics

Panics if index is less than the number of elements of the array to which &self points.

source

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

Does a volatile read of the element at index.

source

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

Does a volatile write of the element at index.

source

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

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 v = [0u8; 32];
let v_ref = unsafe { VolatileArrayRef::new(v.as_mut_ptr(), v.len()) };

let mut buf = [5u8; 16];
v_ref.copy_to(&mut buf[..]);
for &v in &buf[..] {
    assert_eq!(v, 0);
}
source

pub fn copy_to_volatile_slice<S: BitmapSlice>( &self, slice: VolatileSlice<'_, S> )

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

The copies happen in an undefined order.

§Examples
let mut v = [0u8; 32];
let v_ref = unsafe { VolatileArrayRef::<u8>::new(v.as_mut_ptr(), v.len()) };
let mut buf = [5u8; 16];
let v_ref2 = unsafe { VolatileArrayRef::<u8>::new(buf.as_mut_ptr(), buf.len()) };

v_ref.copy_to_volatile_slice(v_ref2.to_slice());
for &v in &buf[..] {
    assert_eq!(v, 0);
}
source

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

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 v = [0u8; 32];
let v_ref = unsafe { VolatileArrayRef::<u8>::new(v.as_mut_ptr(), v.len()) };

let buf = [5u8; 64];
v_ref.copy_from(&buf[..]);
for &val in &v[..] {
    assert_eq!(5u8, val);
}

Trait Implementations§

source§

impl<'a, T: Clone, B: Clone> Clone for VolatileArrayRef<'a, T, B>

source§

fn clone(&self) -> VolatileArrayRef<'a, T, B>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, T: Debug, B: Debug> Debug for VolatileArrayRef<'a, T, B>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, B: BitmapSlice> From<VolatileSlice<'a, B>> for VolatileArrayRef<'a, u8, B>

source§

fn from(slice: VolatileSlice<'a, B>) -> Self

Converts to this type from the input type.
source§

impl<'a, T: Copy, B: Copy> Copy for VolatileArrayRef<'a, T, B>

Auto Trait Implementations§

§

impl<'a, T, B = ()> !RefUnwindSafe for VolatileArrayRef<'a, T, B>

§

impl<'a, T, B = ()> !Send for VolatileArrayRef<'a, T, B>

§

impl<'a, T, B = ()> !Sync for VolatileArrayRef<'a, T, B>

§

impl<'a, T, B> Unpin for VolatileArrayRef<'a, T, B>
where B: Unpin,

§

impl<'a, T, B = ()> !UnwindSafe for VolatileArrayRef<'a, T, B>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.