Struct IntoIter

pub struct IntoIter<T, A: Allocator = Global> { pub(in ::vec) buf: NonNull<T>, pub(in ::vec) phantom: PhantomData<T>, pub(in ::vec) cap: usize, pub(in ::vec) alloc: ManuallyDrop<A>, pub(in ::vec) ptr: NonNull<T>, pub(in ::vec) end: *const T }

An iterator that moves out of a vector.

This struct is created by the into_iter method on Vec (provided by the IntoIterator trait).

Example

let v = vec![0, 1, 2];
let iter: std::vec::IntoIter<_> = v.into_iter();

Fields

buf: NonNull<T>
phantom: PhantomData<T>
cap: usize
alloc: ManuallyDrop<A>
ptr: NonNull<T>
end: *const T

If T is a ZST, this is actually ptr+len. This encoding is picked so that ptr == end is a quick test for the Iterator being empty, that works for both ZST and non-ZST. For non-ZSTs the pointer is treated as NonNull<T>

Implementations

impl<T, A: Allocator> IntoIter<T, A>

fn as_slice(&self) -> &[T]

Returns the remaining items of this iterator as a slice.

Examples

let vec = vec!['a', 'b', 'c'];
let mut into_iter = vec.into_iter();
assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
let _ = into_iter.next().unwrap();
assert_eq!(into_iter.as_slice(), &['b', 'c']);
fn as_mut_slice(&mut self) -> &mut [T]

Returns the remaining items of this iterator as a mutable slice.

Examples

let vec = vec!['a', 'b', 'c'];
let mut into_iter = vec.into_iter();
assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
into_iter.as_mut_slice()[2] = 'z';
assert_eq!(into_iter.next().unwrap(), 'a');
assert_eq!(into_iter.next().unwrap(), 'b');
assert_eq!(into_iter.next().unwrap(), 'z');
fn allocator(&self) -> &A

Returns a reference to the underlying allocator.

fn as_raw_mut_slice(&mut self) -> *mut [T]
fn forget_allocation_drop_remaining(&mut self)

Drops remaining elements and relinquishes the backing allocation.

This method guarantees it won't panic before relinquishing the backing allocation.

This is roughly equivalent to the following, but more efficient

# let mut vec = Vec::<u8>::with_capacity(10);
# let ptr = vec.as_mut_ptr();
# let mut into_iter = vec.into_iter();
let mut into_iter = std::mem::replace(&mut into_iter, Vec::new().into_iter());
(&mut into_iter).for_each(drop);
std::mem::forget(into_iter);
# // FIXME(https://github.com/rust-lang/miri/issues/3670):
# // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak.
# drop(unsafe { Vec::<u8>::from_raw_parts(ptr, 0, 10) });

This method is used by in-place iteration, refer to the vec::in_place_collect documentation for an overview.

fn forget_remaining_elements(&mut self)

Forgets to Drop the remaining elements while still allowing the backing allocation to be freed.

This method does not consume self, and leaves deallocation to impl Drop for IntoIter. If consuming self is possible, consider calling [Self::forget_remaining_elements_and_dealloc()] instead.

fn forget_remaining_elements_and_dealloc(self)

Forgets to Drop the remaining elements and frees the backing allocation. Consuming version of [Self::forget_remaining_elements()].

This can be used in place of drop(self) when self is known to be exhausted, to avoid producing a needless drop_in_place::<[T]>().

unsafe fn dealloc_only(&mut self)

Frees the allocation, without checking or dropping anything else.

The safe version of this method is [Self::forget_remaining_elements_and_dealloc()]. This function exists only to share code between that method and the impl Drop.

Safety

This function must only be called with an IntoIter that is not going to be dropped or otherwise used in any way, either because it is being forgotten or because its Drop is already executing; otherwise a double-free will occur, and possibly a read from freed memory if there are any remaining elements.

fn into_vecdeque(self) -> VecDeque<T, A>

Trait Implementations

impl<T> AsVecIntoIter for IntoIter<T>

type Item = T;
fn as_into_iter(&mut self) -> &mut IntoIter<Self::Item>

impl<T, A> Default for IntoIter<T, A> where A: Allocator + Default,

fn default() -> Self

Creates an empty vec::IntoIter.

# use std::vec;
let iter: vec::IntoIter<u8> = Default::default();
assert_eq!(iter.len(), 0);
assert_eq!(iter.as_slice(), &[]);

impl<T, A: Allocator> AsRef<[T]> for IntoIter<T, A>

fn as_ref(&self) -> &[T]

impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A>

fn next_back(&mut self) -> Option<T>
fn next_chunk_back<const N: usize>(&mut self) -> Result<[T; N], IntoIter<T, N>>
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>

impl<T, A: Allocator> Drop for IntoIter<T, A>

fn drop(&mut self)

impl<T, A: Allocator> ExactSizeIterator for IntoIter<T, A>

fn is_empty(&self) -> bool

impl<T, A: Allocator> FusedIterator for IntoIter<T, A>

impl<T, A: Allocator> InPlaceIterable for IntoIter<T, A>

const EXPAND_BY: Option<NonZero<usize>> = _;
const MERGE_BY: Option<NonZero<usize>> = _;

impl<T, A: Allocator> Iterator for IntoIter<T, A>

type Item = T;
fn next(&mut self) -> Option<T>
fn size_hint(&self) -> (usize, Option<usize>)
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
fn count(self) -> usize
fn last(self) -> Option<T>
fn next_chunk<const N: usize>(&mut self) -> Result<[T; N], IntoIter<T, N>>
fn fold<B, F>(self, accum: B, f: F) -> B
where
    F: FnMut(B, Self::Item) -> B,
fn try_fold<B, F, R>(&mut self, accum: B, f: F) -> R
where
    Self: Sized,
    F: FnMut(B, Self::Item) -> R,
    R: Try<Output = B>,
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> Self::Item
where
    Self: TrustedRandomAccessNoCoerce,

impl<T, A: Allocator> SourceIter for IntoIter<T, A>

type Source = IntoIter<T, A>;
unsafe fn as_inner(&mut self) -> &mut Self::Source

impl<T, A: Allocator> TrustedFused for IntoIter<T, A>

impl<T, A: Allocator> TrustedLen for IntoIter<T, A>

impl<T, A: Allocator> TrustedRandomAccessNoCoerce for IntoIter<T, A> where T: NonDrop,

const MAY_HAVE_SIDE_EFFECT: bool = false;

impl<T: Clone, A: Allocator + Clone> Clone for IntoIter<T, A>

fn clone(&self) -> Self

impl<T: Debug, A: Allocator> Debug for IntoIter<T, A>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<T: Send, A: Allocator + Send> Send for IntoIter<T, A>

impl<T: Sync, A: Allocator + Sync> Sync for IntoIter<T, A>

impl<T: UnwindSafe, A: Allocator + UnwindSafe> UnwindSafe for IntoIter<T, A>

Auto Trait Implementations

impl<T, A> Freeze for IntoIter<T, A> where NonNull<T>: Freeze + Freeze, PhantomData<T>: Freeze, ManuallyDrop<A>: Freeze, *const T: Freeze,

impl<T, A> RefUnwindSafe for IntoIter<T, A> where NonNull<T>: RefUnwindSafe + RefUnwindSafe, PhantomData<T>: RefUnwindSafe, ManuallyDrop<A>: RefUnwindSafe, *const T: RefUnwindSafe,

impl<T, A> Unpin for IntoIter<T, A> where NonNull<T>: Unpin + Unpin, PhantomData<T>: Unpin, ManuallyDrop<A>: Unpin, *const T: Unpin,

impl<T, A> UnsafeUnpin for IntoIter<T, A> where NonNull<T>: UnsafeUnpin + UnsafeUnpin, PhantomData<T>: UnsafeUnpin, ManuallyDrop<A>: UnsafeUnpin, *const T: UnsafeUnpin,

Blanket Implementations

impl<I> IntoIterator for IntoIter<T, A> where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

impl<T> Any for IntoIter<T, A> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for IntoIter<T, A> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for IntoIter<T, A> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for IntoIter<T, A> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for IntoIter<T, A>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for IntoIter<T, A> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for IntoIter<T, A>

impl<T> ToOwned for IntoIter<T, A> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for IntoIter<T, A> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for IntoIter<T, A> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for IntoIter<T, A> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>