unsafe fn from_iter_exact(iter: impl iter::Iterator<Item = T>, len: usize) -> Arc<[T]> {
        // Panic guard while cloning T elements.
        // In the event of a panic, elements that have been written
        // into the new ArcInner will be dropped, then the memory freed.
        struct Guard<T> {
            mem: NonNull<u8>,
            elems: *mut T,
            layout: Layout,
            n_elems: usize,
        }

        impl<T> Drop for Guard<T> {
            fn drop(&mut self) {
                unsafe {
                    let slice = from_raw_parts_mut(self.elems, self.n_elems);
                    ptr::drop_in_place(slice);

                    Global.dealloc(self.mem.cast(), self.layout);
                }
            }
        }

        unsafe {
            let ptr = Self::allocate_for_slice(len);

            let mem = ptr as *mut _ as *mut u8;
            let layout = Layout::for_value(&*ptr);

            // Pointer to first element
            let elems = &mut (*ptr).data as *mut [T] as *mut T;

            let mut guard = Guard { mem: NonNull::new_unchecked(mem), elems, layout, n_elems: 0 };

            for (i, item) in iter.enumerate() {
                ptr::write(elems.add(i), item);
                guard.n_elems += 1;
            }

            // All clear. Forget the guard so it doesn't free the new ArcInner.
            mem::forget(guard);

            Self::from_ptr(ptr)
        }
    }
/// Constructs an `Arc<[T]>` from an iterator known to be of a certain size.
///
/// Behavior is undefined should the size be wrong.
Constructs an `Arc<[T]>` from an iterator known to be of a certain size.
Behavior is undefined should the size be wrong.
Constructs an ` Arc< [ T ] > ` from an iterator known to be of a certain size . Behavior is undefined should the size be wrong .
unsafe fn from_iter_exact(iter: impl iter::Iterator<Item = T>, len: usize) -> Arc<[T]> {
        // Panic guard while cloning T elements.
        // In the event of a panic, elements that have been written
        // into the new ArcInner will be dropped, then the memory freed.
        struct Guard<T> {
            mem: NonNull<u8>,
            elems: *mut T,
            layout: Layout,
            n_elems: usize,
        }
        impl<T> Drop for Guard<T> {
            fn drop(&mut self) {
                unsafe {
                    let slice = from_raw_parts_mut(self.elems, self.n_elems);
                    ptr::drop_in_place(slice);
                    Global.dealloc(self.mem.cast(), self.layout);
                }
            }
        }
        unsafe {
            let ptr = Self::allocate_for_slice(len);
            let mem = ptr as *mut _ as *mut u8;
            let layout = Layout::for_value(&*ptr);
            // Pointer to first element
            let elems = &mut (*ptr).data as *mut [T] as *mut T;
            let mut guard = Guard { mem: NonNull::new_unchecked(mem), elems, layout, n_elems: 0 };
            for (i, item) in iter.enumerate() {
                ptr::write(elems.add(i), item);
                guard.n_elems += 1;
            }
            // All clear. Forget the guard so it doesn't free the new ArcInner.
            mem::forget(guard);
            Self::from_ptr(ptr)
        }
    }
unsafe fn from_iter_exact ( iter : impl iter :: Iterator < Item = T > , len : usize ) -> Arc < [ T ] > { // Panic guard while cloning T elements. // In the event of a panic, elements that have been written // into the new ArcInner will be dropped, then the memory freed. struct Guard < T > { mem : NonNull < u8 > , elems : * mut T , layout : Layout , n_elems : usize , } impl < T > Drop for Guard < T > { fn drop ( & mut self ) { unsafe { let slice = from_raw_parts_mut ( self . elems , self . n_elems ) ; ptr :: drop_in_place ( slice ) ; Global . dealloc ( self . mem . cast ( ) , self . layout ) ; } } } unsafe { let ptr = Self :: allocate_for_slice ( len ) ; let mem = ptr as * mut _ as * mut u8 ; let layout = Layout :: for_value ( & * ptr ) ; // Pointer to first element let elems = & mut ( * ptr ) . data as * mut [ T ] as * mut T ; let mut guard = Guard { mem : NonNull :: new_unchecked ( mem ) , elems , layout , n_elems : 0 } ; for ( i , item ) in iter . enumerate ( ) { ptr :: write ( elems . add ( i ) , item ) ; guard . n_elems += 1 ; } // All clear. Forget the guard so it doesn't free the new ArcInner. mem :: forget ( guard ) ; Self :: from_ptr ( ptr ) } }
Constructs an `Arc<[T]>` from an iterator known to be of a certain size.
Constructs an ` Arc< [ T ] > ` from an iterator known to be of a certain size .
iter
impl iter::Iterator<Item = T>
len
usize
iter
impl iter::Iterator<Item = T>
len
usize