Struct Drain

pub(in ::array) struct Drain<'l, 'f, T, F> { pub(in ::array::drain) ptr: NonNull<T>, pub(in ::array::drain) end_or_len: *mut T, pub(in ::array::drain) f: &'f mut F, pub(in ::array::drain) l: PhantomData<&'l mut [T]> }

See Drain::new; this is our fake iterator.

Fields

ptr: NonNull<T>

The pointer to the next element to return, or the past-the-end location if the drainer is empty.

This address will be used for all ZST elements, never changed. As we "own" this array, we dont need to store any lifetime.

end_or_len: *mut T

For non-ZSTs, the non-null pointer to the past-the-end element. For ZSTs, this is the number of unprocessed items.

f: &'f mut F
l: PhantomData<&'l mut [T]>

Implementations

impl<'l, 'f, T, U, F: FnMut(T) -> U> Drain<'l, 'f, T, F>

const unsafe fn new<const N: usize>(array: &'l mut ManuallyDrop<[T; N]>, f: &'f mut F) -> Self

This function returns a function that lets you index the given array in const. As implemented it can optimize better than iterators, and can be constified. It acts like a sort of guard (owns the array) and iterator combined, which can be implemented as it is a struct that implements const fn. The only method you're really allowed to call is next(), anything else is more or less UB, hence this function being unsafe. Moved elements will not be dropped. This will also not actually store the array.

SAFETY: must only be called N times. Thou shalt not drop the array either.

Trait Implementations

impl<T, F> Drop for Drain<'_, '_, T, F>

fn drop(&mut self)

Auto Trait Implementations

impl<'l, 'f, T, F> !Send for Drain<'l, 'f, T, F>

impl<'l, 'f, T, F> !Sync for Drain<'l, 'f, T, F>

impl<'l, 'f, T, F> !UnwindSafe for Drain<'l, 'f, T, F>

impl<'l, 'f, T, F> Freeze for Drain<'l, 'f, T, F> where NonNull<T>: Freeze, *mut T: Freeze, &'f mut F: Freeze, PhantomData<&'l mut [T]>: Freeze,

impl<'l, 'f, T, F> RefUnwindSafe for Drain<'l, 'f, T, F> where NonNull<T>: RefUnwindSafe, *mut T: RefUnwindSafe, &'f mut F: RefUnwindSafe, PhantomData<&'l mut [T]>: RefUnwindSafe,

impl<'l, 'f, T, F> Unpin for Drain<'l, 'f, T, F> where NonNull<T>: Unpin, *mut T: Unpin, &'f mut F: Unpin, PhantomData<&'l mut [T]>: Unpin,

impl<'l, 'f, T, F> UnsafeUnpin for Drain<'l, 'f, T, F> where NonNull<T>: UnsafeUnpin, *mut T: UnsafeUnpin, &'f mut F: UnsafeUnpin, PhantomData<&'l mut [T]>: UnsafeUnpin,

Blanket Implementations

impl<T> Any for Drain<'l, 'f, T, F> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Drain<'l, 'f, T, F> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Drain<'l, 'f, T, F> where T: ?Sized,

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

impl<T> From<T> for Drain<'l, 'f, T, F>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for Drain<'l, 'f, T, F> where T: ?Sized,

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

impl<T> SizedTypeProperties for Drain<'l, 'f, T, F>

impl<T, U> Into<U> for Drain<'l, 'f, T, F> 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 Drain<'l, 'f, T, F> 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 Drain<'l, 'f, T, F> where U: TryFrom<T>,

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