/// Extend the arrayvec from the iterable.
///
/// ## Safety
///
/// Unsafe because if CHECK is false, the length of the input is not checked.
/// The caller must ensure the length of the input fits in the capacity.
Extend the arrayvec from the iterable.
Extend the arrayvec from the iterable .
pub(crate) unsafe fn extend_from_iter<I, const CHECK: bool>(&mut self, iterable: I)
        where I: IntoIterator<Item = T>
    {
        let take = self.capacity() - self.len();
        let len = self.len();
        let mut ptr = raw_ptr_add(self.as_mut_ptr(), len);
        let end_ptr = raw_ptr_add(ptr, take);
        // Keep the length in a separate variable, write it back on scope
        // exit. To help the compiler with alias analysis and stuff.
        // We update the length to handle panic in the iteration of the
        // user's iterator, without dropping any elements on the floor.
        let mut guard = ScopeExitGuard {
            value: &mut self.len,
            data: len,
            f: move |&len, self_len| {
                **self_len = len as LenUint;
            }
        };
        let mut iter = iterable.into_iter();
        loop {
            if let Some(elt) = iter.next() {
                if ptr == end_ptr && CHECK { extend_panic(); }
                debug_assert_ne!(ptr, end_ptr);
                ptr.write(elt);
                ptr = raw_ptr_add(ptr, 1);
                guard.data += 1;
            } else {
                return; // success
            }
        }
    }
pub ( crate ) unsafe fn extend_from_iter < I , const CHECK : bool > ( & mut self , iterable : I ) where I : IntoIterator < Item = T > { let take = self . capacity ( ) - self . len ( ) ; let len = self . len ( ) ; let mut ptr = raw_ptr_add ( self . as_mut_ptr ( ) , len ) ; let end_ptr = raw_ptr_add ( ptr , take ) ; // Keep the length in a separate variable, write it back on scope // exit. To help the compiler with alias analysis and stuff. // We update the length to handle panic in the iteration of the // user's iterator, without dropping any elements on the floor. let mut guard = ScopeExitGuard { value : & mut self . len , data : len , f : move | & len , self_len | { * * self_len = len as LenUint ; } } ; let mut iter = iterable . into_iter ( ) ; loop { if let Some ( elt ) = iter . next ( ) { if ptr == end_ptr && CHECK { extend_panic ( ) ; } debug_assert_ne ! ( ptr end_ptr ) ; ptr . write ( elt ) ; ptr = raw_ptr_add ( ptr , 1 ) ; guard . data += 1 ; } else { return ; // success } } }
Extend the arrayvec from the iterable.
Extend the arrayvec from the iterable .
&mut self
iterable
I
safety
Unsafe because if CHECK is false, the length of the input is not checked.
The caller must ensure the length of the input fits in the capacity.
Unsafe because if CHECK is false the length of the input is not checked . The caller must ensure the length of the input fits in the capacity .