Trait generic_array::sequence::Shorten

source ·
pub unsafe trait Shorten<T>: Sized + GenericSequence<T> {
    type Shorter: Lengthen<T, Longer = Self>;

    // Required methods
    fn pop_back(self) -> (Self::Shorter, T);
    fn pop_front(self) -> (T, Self::Shorter);
}
Expand description

Defines a GenericSequence which can be shortened by removing the first or last element from it.

Additionally, any shortened sequence can be lengthened by appending or prepending an element to it.

§Safety

While the pop_back and pop_front methods are marked safe, care must be taken when implementing them.

Required Associated Types§

source

type Shorter: Lengthen<T, Longer = Self>

GenericSequence that has one less element than Self

Required Methods§

source

fn pop_back(self) -> (Self::Shorter, T)

Returns a new array without the last element, and the last element.

Example:


let a = arr![1, 2, 3, 4];

let (init, last) = a.pop_back();

assert_eq!(init, arr![1, 2, 3]);
assert_eq!(last, 4);
source

fn pop_front(self) -> (T, Self::Shorter)

Returns a new array without the first element, and the first element. Example:


let a = arr![1, 2, 3, 4];

let (head, tail) = a.pop_front();

assert_eq!(head, 1);
assert_eq!(tail, arr![2, 3, 4]);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, N> Shorten<T> for GenericArray<T, N>
where N: Sub<B1> + ArrayLength, Sub1<N>: ArrayLength + Add<B1, Output = N>, Add1<Sub1<N>>: ArrayLength,

§

type Shorter = GenericArray<T, <N as Sub<B1>>::Output>