slice_dst

Trait SliceDst

Source
pub unsafe trait SliceDst {
    // Required methods
    fn layout_for(len: usize) -> Layout;
    fn retype(ptr: NonNull<[()]>) -> NonNull<Self>;
}
Expand description

A custom slice-based dynamically sized type.

Unless you are making a custom slice DST that needs to pack its length extremely well, then you should just use SliceWithHeader instead.

Required Methods§

Source

fn layout_for(len: usize) -> Layout

Get the layout of the slice-containing type with the given slice length.

Source

fn retype(ptr: NonNull<[()]>) -> NonNull<Self>

Add the type onto an untyped pointer.

This is used to add the type on during allocation. This function is required because otherwise Rust cannot guarantee that the metadata on both sides of the cast lines up.

§Safety

The implementation must not dereference the input pointer. This function is safe because it must work for all input pointers, without asserting the pointer’s validity of any kind, express or implied, including but not limited to the validities of alignment, fitness for dereferencing and nullity.

In practice, this means that the implementation should just be a pointer cast.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> SliceDst for [T]

Implementors§

Source§

impl<Header> SliceDst for StrWithHeader<Header>

Source§

impl<Header, Item> SliceDst for SliceWithHeader<Header, Item>