pub trait Ext<T> {
fn split_while(&self, test: impl FnMut(&T) -> bool) -> (&[T], &[T]);
fn copy_tail(&mut self, start: usize) -> Option<&mut [T]>
where
T: Copy;
}
impl<T> Ext<T> for [T] {
fn split_while(&self, mut test: impl FnMut(&T) -> bool) -> (&[T], &[T]) {
let end = self.iter().take_while(|value| test(value)).count();
unsafe { self.split_at_unchecked(end) }
}
fn copy_tail(&mut self, start: usize) -> Option<&mut [T]>
where
T: Copy,
{
let len = self.len().checked_sub(start)?;
self.copy_within(start.., 0);
Some(&mut self[..len])
}
}