Skip to main content

Drain

Struct Drain 

Source
pub(super) struct Drain<'l, 'f, T, const N: usize, F> {
    ptr: NonNull<T>,
    end: *mut T,
    f: &'f mut F,
    l: PhantomData<&'l mut [T; N]>,
}
🔬This is a nightly-only experimental API. (array_try_map #79711)
Expand description

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

Fields§

§ptr: NonNull<T>
🔬This is a nightly-only experimental API. (array_try_map #79711)

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: *mut T
🔬This is a nightly-only experimental API. (array_try_map #79711)

For non-ZSTs, the non-null pointer to the past-the-end element. For ZSTs, this is null.

§f: &'f mut F
🔬This is a nightly-only experimental API. (array_try_map #79711)
§l: PhantomData<&'l mut [T; N]>
🔬This is a nightly-only experimental API. (array_try_map #79711)

Implementations§

Source§

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

Source

pub(super) const unsafe fn new( 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; in that regard it is somewhat similar to an array::Iter implementing UncheckedIterator. 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§

Source§

impl<T, const N: usize, F> Drop for Drain<'_, '_, T, N, F>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, U, const N: usize, F> FnMut(usize) for &mut Drain<'_, '_, T, N, F>
where F: FnMut(T) -> U,

Source§

extern "rust-call" fn call_mut( &mut self, (_): (usize,), ) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits #29625)
Performs the call operation.
Source§

impl<T, U, const N: usize, F> FnOnce(usize) for &mut Drain<'_, '_, T, N, F>
where F: FnMut(T) -> U,

Source§

extern "rust-call" fn call_once(self, args: (usize,)) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits #29625)

This implementation is useless.

Source§

type Output = U

The returned type after the call operator is used.

Auto Trait Implementations§

§

impl<'l, 'f, T, const N: usize, F> Freeze for Drain<'l, 'f, T, N, F>

§

impl<'l, 'f, T, const N: usize, F> RefUnwindSafe for Drain<'l, 'f, T, N, F>

§

impl<'l, 'f, T, const N: usize, F> !Send for Drain<'l, 'f, T, N, F>

§

impl<'l, 'f, T, const N: usize, F> !Sync for Drain<'l, 'f, T, N, F>

§

impl<'l, 'f, T, const N: usize, F> Unpin for Drain<'l, 'f, T, N, F>

§

impl<'l, 'f, T, const N: usize, F> UnsafeUnpin for Drain<'l, 'f, T, N, F>

§

impl<'l, 'f, T, const N: usize, F> !UnwindSafe for Drain<'l, 'f, T, N, F>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type #102070)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.