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]>,
}array_try_map #79711)Expand description
See Drain::new; this is our fake iterator.
Fields§
§ptr: NonNull<T>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 Tarray_try_map #79711)For non-ZSTs, the non-null pointer to the past-the-end element. For ZSTs, this is null.
f: &'f mut Farray_try_map #79711)l: PhantomData<&'l mut [T; N]>array_try_map #79711)Implementations§
Source§impl<'l, 'f, T, U, const N: usize, F: FnMut(T) -> U> Drain<'l, 'f, T, N, F>
impl<'l, 'f, T, U, const N: usize, F: FnMut(T) -> U> Drain<'l, 'f, T, N, F>
Sourcepub(super) const unsafe fn new(
array: &'l mut ManuallyDrop<[T; N]>,
f: &'f mut F,
) -> Self
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, U, const N: usize, F> FnMut(usize) for &mut Drain<'_, '_, T, N, F>where
F: FnMut(T) -> U,
impl<T, U, const N: usize, F> FnMut(usize) for &mut Drain<'_, '_, T, N, F>where
F: FnMut(T) -> U,
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>where
T: RefUnwindSafe,
F: RefUnwindSafe,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type #102070)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more