box_iter/
trait.rs

1use core::{alloc::Allocator, ptr::NonNull};
2use alloc::boxed::Box;
3
4pub trait BoxIntoIter {
5    type Item;
6    type IntoIter: Iterator<Item = Self::Item>;
7    
8    fn into_iter (self) -> Self::IntoIter;
9}
10
11impl<T, A: Allocator> BoxIntoIter for Box<[T], A> {
12    type Item = T;
13    type IntoIter = super::IntoIter<T, A>;
14
15    #[inline(always)]
16    fn into_iter (self) -> Self::IntoIter {
17        let (ptr, alloc) = Box::into_raw_with_allocator(self);
18        let range = unsafe { &mut *ptr }.as_mut_ptr_range();
19
20        unsafe {
21            super::IntoIter {
22                ptr: NonNull::new_unchecked(ptr),
23                range,
24                alloc
25            } 
26        }
27    }
28}