unsafe fn allocate_for_layout(
        value_layout: Layout,
        mem_to_arcinner: impl FnOnce(*mut u8) -> *mut ArcInner<T>,
    ) -> *mut ArcInner<T> {
        // Calculate layout using the given value layout.
        // Previously, layout was calculated on the expression
        // `&*(ptr as *const ArcInner<T>)`, but this created a misaligned
        // reference (see #54908).
        let layout = Layout::new::<ArcInner<()>>().extend(value_layout).unwrap().0.pad_to_align();

        let mem = Global
            .alloc(layout, AllocInit::Uninitialized)
            .unwrap_or_else(|_| handle_alloc_error(layout));

        // Initialize the ArcInner
        let inner = mem_to_arcinner(mem.ptr.as_ptr());
        debug_assert_eq!(unsafe { Layout::for_value(&*inner) }, layout);

        unsafe {
            ptr::write(&mut (*inner).strong, atomic::AtomicUsize::new(1));
            ptr::write(&mut (*inner).weak, atomic::AtomicUsize::new(1));
        }

        inner
    }
/// Allocates an `ArcInner<T>` with sufficient space for
/// a possibly-unsized inner value where the value has the layout provided.
///
/// The function `mem_to_arcinner` is called with the data pointer
/// and must return back a (potentially fat)-pointer for the `ArcInner<T>`.
Allocates an `ArcInner` with sufficient space for
a possibly-unsized inner value where the value has the layout provided.

The function `mem_to_arcinner` is called with the data pointer
and must return back a (potentially fat)-pointer for the `ArcInner`.
Allocates an ` ArcInner ` with sufficient space for a possibly - unsized inner value where the value has the layout provided . The function ` mem_to_arcinner ` is called with the data pointer and must return back a ( potentially fat ) - pointer for the ` ArcInner ` .
unsafe fn allocate_for_layout(
        value_layout: Layout,
        mem_to_arcinner: impl FnOnce(*mut u8) -> *mut ArcInner<T>,
    ) -> *mut ArcInner<T> {
        // Calculate layout using the given value layout.
        // Previously, layout was calculated on the expression
        // `&*(ptr as *const ArcInner<T>)`, but this created a misaligned
        // reference (see #54908).
        let layout = Layout::new::<ArcInner<()>>().extend(value_layout).unwrap().0.pad_to_align();
        let mem = Global
            .alloc(layout, AllocInit::Uninitialized)
            .unwrap_or_else(|_| handle_alloc_error(layout));
        // Initialize the ArcInner
        let inner = mem_to_arcinner(mem.ptr.as_ptr());
        debug_assert_eq!(unsafe { Layout::for_value(&*inner) }, layout);
        unsafe {
            ptr::write(&mut (*inner).strong, atomic::AtomicUsize::new(1));
            ptr::write(&mut (*inner).weak, atomic::AtomicUsize::new(1));
        }
        inner
    }
unsafe fn allocate_for_layout ( value_layout : Layout , mem_to_arcinner : impl FnOnce ( * mut u8 ) -> * mut ArcInner < T > , ) -> * mut ArcInner < T > { // Calculate layout using the given value layout. // Previously, layout was calculated on the expression // `&*(ptr as *const ArcInner<T>)`, but this created a misaligned // reference (see #54908). let layout = Layout :: new :: < ArcInner < ( ) > > ( ) . extend ( value_layout ) . unwrap ( ) . 0 . pad_to_align ( ) ; let mem = Global . alloc ( layout , AllocInit :: Uninitialized ) . unwrap_or_else ( | _ | handle_alloc_error ( layout ) ) ; // Initialize the ArcInner let inner = mem_to_arcinner ( mem . ptr . as_ptr ( ) ) ; debug_assert_eq ! ( unsafe { Layout for_value ( inner ) } layout ) ; unsafe { ptr :: write ( & mut ( * inner ) . strong , atomic :: AtomicUsize :: new ( 1 ) ) ; ptr :: write ( & mut ( * inner ) . weak , atomic :: AtomicUsize :: new ( 1 ) ) ; } inner }
Allocates an `ArcInner<T>` with sufficient space for
a possibly-unsized inner value where the value has the layout provided.
Allocates an ` ArcInner<T > ` with sufficient space for a possibly - unsized inner value where the value has the layout provided .
value_layout
Layout
mem_to_arcinner
impl FnOnce(*mut u8) -> *mut ArcInner<T>
value_layout
Layout
mem_to_arcinner
impl FnOnce(*mut u8) -> *mut ArcInner<T>