dstify 0.2.1

safe construction of custom dynamically-sized types (DSTs)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use super::{DropGuard, Sealed, SmartPointer};
use alloc::{alloc::Layout, boxed::Box, sync::Arc};

impl<T: ?Sized> Sealed for alloc::sync::Arc<T> {}

impl<T: ?Sized> SmartPointer<T> for Arc<T> {
    type Guard = DropGuard;

    unsafe fn alloc(layout: Layout) -> (*mut u8, Self::Guard) {
        unsafe { Box::<T>::alloc(layout) }
    }

    unsafe fn cast(base: *mut T) -> Self {
        unsafe { Box::from_raw(base) }.into()
    }
}