Struct write_only::WriteOnlySlice[][src]

pub struct WriteOnlySlice<'a, T: 'a> { /* fields omitted */ }
Expand description

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

Implementations

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

Trait Implementations

Performs the conversion.

Puts the value at index to the given value, dropping the old value. Read more

Puts the value at index to the given value, dropping the old value without checking bounds. Read more

Clones the elements from src into self, starting at offset, dropping the old values. Read more

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

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

Copies the elements from src into self. Read more

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

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

Performs the conversion.

Performs the conversion.

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.