I've regularly written code where the following methods would be useful:
impl<T> [T] { // also mut versions
fn pop_front(&mut &self) -> Option<&T>;
fn pop_front_chunk<const N: usize>(&mut &self) -> Option<&[T; N]>;
fn pop_back(&mut &self) -> Option<&T>;
fn pop_back_chunk<const N: usize>(&mut &self) -> Option<&[T; N]>;
}
Each of these methods acting like the corresponding split_first
/split_last
methods, except instead of returning a tuple they modify self
in-place to remove the returned value. So e.g. calling pop_front
in a loop would return values equivalently to constructing an iterator and
Would anyone else find methods like these useful?