Skip to main content

Dst

Trait Dst 

Source
pub unsafe trait Dst {
    // Required methods
    fn len(&self) -> usize;
    fn layout(len: usize) -> Result<Layout, LayoutError>;
    fn retype(ptr: NonNull<u8>, len: usize) -> NonNull<Self>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A dynamically sized type.

§Safety

Must be implemented as described.

Required Methods§

Source

fn len(&self) -> usize

The length of the DST.

Note that this is NOT the size of the type, for that you should use Layout::for_value or Dst::layout.

Source

fn layout(len: usize) -> Result<Layout, LayoutError>

Returns the layout of the DST, assuming it has the given length.

§Errors

Returns a LayoutError if calculation of the layout fails.

Source

fn retype(ptr: NonNull<u8>, len: usize) -> NonNull<Self>

Convert the given thin pointer to a fat pointer to the DST, adding the length to the metadata.

§Safety

This function is safe but the returned pointer is not necessarily safe to dereference.

Provided Methods§

Source

fn is_empty(&self) -> bool

Counterpart to len. Mainly exists to please clippy.

The default implementation simply checks if the len equals 0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Dst for str

Source§

impl<T> Dst for [T]

Implementors§