Skip to main content

AllocDst

Trait AllocDst 

Source
pub unsafe trait AllocDst<T: ?Sized + Dst>: Sized + Borrow<T> {
    // Required method
    unsafe fn try_new_dst<F, E>(
        len: usize,
        layout: Layout,
        init: F,
    ) -> Result<Self, E>
       where F: FnOnce(NonNull<T>) -> Result<(), E>;

    // Provided method
    unsafe fn new_dst<F>(len: usize, layout: Layout, init: F) -> Self
       where F: FnOnce(NonNull<T>) { ... }
}
Expand description

Type that can allocate a DST and store it inside it.

§Safety

Must be implemented as described.

Required Methods§

Source

unsafe fn try_new_dst<F, E>( len: usize, layout: Layout, init: F, ) -> Result<Self, E>
where F: FnOnce(NonNull<T>) -> Result<(), E>,

Allocate the DST with the given length, initialize the data with the given fallible function, and store it in the type.

§Safety

The layout must accurately describe an object of type T with length len. The init function must correctly initialize the data pointed to, or return an error.

§Errors

This function will only return an error in the case that the init function returns an error.

Provided Methods§

Source

unsafe fn new_dst<F>(len: usize, layout: Layout, init: F) -> Self
where F: FnOnce(NonNull<T>),

Allocate the DST with the given length, initialize the data with the given function, and store it in the type.

§Safety

The layout must accurately describe an object of type T with length len. The init function must correctly initialize the data pointed to.

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<T: ?Sized + Dst> AllocDst<T> for Arc<T>

Available on crate feature alloc only.
Source§

unsafe fn try_new_dst<F, E>( len: usize, layout: Layout, init: F, ) -> Result<Self, E>
where F: FnOnce(NonNull<T>) -> Result<(), E>,

Source§

impl<T: ?Sized + Dst> AllocDst<T> for Box<T>

Available on crate feature alloc only.
Source§

unsafe fn try_new_dst<F, E>( len: usize, layout: Layout, init: F, ) -> Result<Self, E>
where F: FnOnce(NonNull<T>) -> Result<(), E>,

Source§

impl<T: ?Sized + Dst> AllocDst<T> for Rc<T>

Available on crate feature alloc only.
Source§

unsafe fn try_new_dst<F, E>( len: usize, layout: Layout, init: F, ) -> Result<Self, E>
where F: FnOnce(NonNull<T>) -> Result<(), E>,

Implementors§