slice_dst

Trait AllocSliceDst

Source
pub unsafe trait AllocSliceDst<S: ?Sized + SliceDst> {
    // Required method
    unsafe fn new_slice_dst<I>(len: usize, init: I) -> Self
       where I: FnOnce(NonNull<S>);
}
Expand description

Types that can allocate a custom slice DST within them.

§Implementation note

For most types, TryAllocSliceDst should be the implementation primitive. This trait can then be implemented in terms of TryAllocSliceDst:

unsafe impl<S: ?Sized + SliceDst> AllocSliceDst<S> for Container<S> {
    unsafe fn new_slice_dst<I>(len: usize, init: I) -> Self
    where
        I: FnOnce(ptr::NonNull<S>),
    {
        enum Void {} // or never (!) once it is stable
        #[allow(clippy::unit_arg)]
        let init = |ptr| Ok::<(), Void>(init(ptr));
        match Self::try_new_slice_dst(len, init) {
            Ok(a) => a,
            Err(void) => match void {},
        }
    }
}

This is not a blanket impl due to coherence rules; if the blanket impl were present, it would be impossible to implement AllocSliceDst instead of TryAllocSliceDst.

Required Methods§

Source

unsafe fn new_slice_dst<I>(len: usize, init: I) -> Self
where I: FnOnce(NonNull<S>),

Create a new custom slice DST.

§Safety

init must properly initialize the object behind the pointer. init receives a fully uninitialized pointer and must not read anything before writing.

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<S: ?Sized + SliceDst> AllocSliceDst<S> for Box<S>

Source§

unsafe fn new_slice_dst<I>(len: usize, init: I) -> Self
where I: FnOnce(NonNull<S>),

Source§

impl<S: ?Sized + SliceDst> AllocSliceDst<S> for Rc<S>

Source§

unsafe fn new_slice_dst<I>(len: usize, init: I) -> Self
where I: FnOnce(NonNull<S>),

Source§

impl<S: ?Sized + SliceDst> AllocSliceDst<S> for Arc<S>

Source§

unsafe fn new_slice_dst<I>(len: usize, init: I) -> Self
where I: FnOnce(NonNull<S>),

Implementors§