SplitTail

Trait SplitTail 

Source
pub trait SplitTail: VecLike + Sized {
    // Required method
    fn split_tail(
        &mut self,
        mid: usize,
    ) -> (&mut [Self::T], TailVec<'_, Self::T, Self>);
}
Expand description

Split at index, tail part is TailVec

Required Methods§

Source

fn split_tail( &mut self, mid: usize, ) -> (&mut [Self::T], TailVec<'_, Self::T, Self>)

Split at index, tail part is TailVec

It can call push and pop etc.

§Panics
  • mid greater than len
§Leaking

If the returned TailVec goes out of scope without being dropped (due to mem::forget, for example), the Self may have lost and leaked elements arbitrarily, including elements outside the range.

§Examples
let mut vec = vec![1, 2, 3];
let (left, mut rest) = vec.split_tail(2);
assert_eq!(left, &mut [1, 2]);
assert_eq!(rest, &mut [3]);

rest.pop().unwrap();
assert_eq!(rest, &mut []);

assert_eq!(rest.pop(), None);
assert_eq!(rest, &mut []);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: VecLike> SplitTail for T