#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;
use core::pin::Pin;
use core::slice::SliceIndex;
pub(crate) fn iter_pin_mut<T>(slice: Pin<&mut [T]>) -> impl Iterator<Item = Pin<&mut T>> {
unsafe { slice.get_unchecked_mut() }
.iter_mut()
.map(|t| unsafe { Pin::new_unchecked(t) })
}
#[cfg(feature = "alloc")]
pub(crate) fn iter_pin_mut_vec<T>(slice: Pin<&mut Vec<T>>) -> impl Iterator<Item = Pin<&mut T>> {
unsafe { slice.get_unchecked_mut() }
.iter_mut()
.map(|t| unsafe { Pin::new_unchecked(t) })
}
#[inline]
pub(crate) fn get_pin_mut<T, I>(slice: Pin<&mut [T]>, index: I) -> Option<Pin<&mut I::Output>>
where
I: SliceIndex<[T]>,
{
unsafe {
slice
.get_unchecked_mut()
.get_mut(index)
.map(|x| Pin::new_unchecked(x))
}
}
#[cfg(feature = "alloc")]
pub(crate) fn get_pin_mut_from_vec<T, I>(
slice: Pin<&mut Vec<T>>,
index: I,
) -> Option<Pin<&mut I::Output>>
where
I: SliceIndex<[T]>,
{
unsafe {
slice
.get_unchecked_mut()
.get_mut(index)
.map(|x| Pin::new_unchecked(x))
}
}