#[repr(transparent)]
pub struct VolatileSlice<'a>(IoBufMut<'a>);
Expand description

A slice of raw memory that supports volatile access. Like std::io::IoSliceMut, this type is guaranteed to be ABI-compatible with libc::iovec but unlike IoSliceMut, it doesn’t automatically deref to &mut [u8].

Tuple Fields§

§0: IoBufMut<'a>

Implementations§

Creates a slice of raw memory that must support volatile access.

Creates a VolatileSlice from a pointer and a length.

Safety

In order to use this method safely, addr must be valid for reads and writes of len bytes and should live for the entire duration of lifetime 'a.

Gets a const pointer to this slice’s memory.

Gets a mutable pointer to this slice’s memory.

Gets the size of this slice.

Advance the starting position of this slice.

Panics if count > self.size().

Shorten the length of the slice.

Has no effect if len > self.size().

Returns this VolatileSlice as an IoBufMut.

Converts a slice of VolatileSlices into a slice of IoBufMuts

Creates a copy of this slice with the address increased by count bytes, and the size reduced by count bytes.

Similar to get_slice but the returned slice outlives this slice.

The returned slice’s lifetime is still limited by the underlying data’s lifetime.

Sets each byte of this slice with the given byte, similar to memset.

The bytes of this slice are accessed in an arbitray order.

Examples
let mut mem = [0u8; 32];
let vslice = VolatileSlice::new(&mut mem[..]);
vslice.write_bytes(45);
for &v in &mem[..] {
    assert_eq!(v, 45);
}

Copies self.size() 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 vslice = VolatileSlice::new(&mut mem[..]);
let mut buf = [5u8; 16];
vslice.copy_to(&mut buf[..]);
for v in &buf[..] {
    assert_eq!(buf[0], 0);
}

Copies self.size() or slice.size() bytes, whichever is smaller, to slice.

The copies happen in an undefined order.

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

Copies self.size() 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 vslice = VolatileSlice::new(&mut mem[..]);
let buf = [5u8; 64];
vslice.copy_from(&buf[..]);
let mut copy_buf = [0u32; 4];
vslice.copy_to(&mut copy_buf);
for i in 0..4 {
    assert_eq!(copy_buf[i], 0x05050505);
}

Returns whether all bytes in this slice are zero or not.

This is optimized for VolatileSlice aligned with 16 bytes.

TODO(b/274840085): Use SIMD for better performance.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Gets a slice of memory at offset that is count bytes in length and supports volatile access.

The PartialEq implementation for VolatileSlice is reflexive, symmetric, and transitive.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.