Struct VolatileWriteOnlySlice

Source
pub struct VolatileWriteOnlySlice<'a, T: 'a> { /* private fields */ }
Expand description

A write-only slice with non-dropping volatile write access.

Implementations§

Source§

impl<'a, T: 'a> VolatileWriteOnlySlice<'a, T>

Source

pub unsafe fn from_raw_parts(data: *mut T, len: usize) -> Self

Forms a write-only slice from a pointer and a length.

The len argument is the number of elements, not the number of bytes.

§Safety

Behavior is undefined if any of the following conditions are violated:

  • data must be valid for reads for len * mem::size_of::<T>() many bytes, and it must be properly aligned. This means in particular:

    • The entire memory range of this slice must be contained within a single allocated object! Slices can never span across multiple allocated objects. See below for an example incorrectly not taking this into account.
    • data must be non-null and aligned even for zero-length slices. One reason for this is that enum layout optimizations may rely on references (including slices of any length) being aligned and non-null to distinguish them from other data. You can obtain a pointer that is usable as data for zero-length slices using ::core::ptr::NonNull::dangling().
  • data must point to len consecutive properly initialized values of type T.

  • The memory referenced by the returned slice must not be mutated for the duration of lifetime 'a, except inside an UnsafeCell.

  • The total size len * mem::size_of::<T>() of the slice must be no larger than isize::MAX. See the safety documentation of pointer::offset.

§Caveat

The lifetime for the returned slice is inferred from its usage. To prevent accidental misuse, it’s suggested to tie the lifetime to whichever source lifetime is safe in the context, such as by providing a helper function taking the lifetime of a host value for the slice, or by explicit annotation.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<'a, T: 'a> From<&'a mut [T]> for VolatileWriteOnlySlice<'a, T>

Source§

fn from(slice: &'a mut [T]) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: 'a> WriteAt<T> for VolatileWriteOnlySlice<'a, T>

Source§

fn write_at(&mut self, index: usize, value: T)

Performs a write of a memory location with the given value without reading or dropping the old value. Read more
Source§

unsafe fn write_at_unchecked(&mut self, index: usize, value: T)

Performs a write of a memory location with the given value without reading or dropping the old value. Read more
Source§

impl<'a, T: 'a> WriteFromSliceAt<T> for VolatileWriteOnlySlice<'a, T>

Source§

fn write_cloning_from_slice_at(&mut self, src: &[T], offset: usize)
where T: Clone,

Copies the elements from src into self. Read more
Source§

fn write_copying_from_slice_at(&mut self, src: &[T], offset: usize)
where T: Copy,

Copies all elements from src into self, using a memcpy. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for VolatileWriteOnlySlice<'a, T>

§

impl<'a, T> RefUnwindSafe for VolatileWriteOnlySlice<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for VolatileWriteOnlySlice<'a, T>

§

impl<'a, T> !Sync for VolatileWriteOnlySlice<'a, T>

§

impl<'a, T> Unpin for VolatileWriteOnlySlice<'a, T>

§

impl<'a, T> UnwindSafe for VolatileWriteOnlySlice<'a, T>
where T: RefUnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.