Deconstruct

Trait Deconstruct 

Source
pub trait Deconstruct<T, const N: usize> {
    // Required methods
    fn uncons(self) -> (T, [T; { _ }]);
    fn unsnoc(self) -> ([T; { _ }], T);
    fn init(self) -> [T; { _ }];
    fn tail(self) -> [T; { _ }];
    fn last(self) -> T
       where [(); { _ }]:;
    fn head(self) -> T
       where [(); { _ }]:;
}
Expand description

Deconstruct some array. Use

let [t, arr @ ..] = [1, 2];

when possible. If the length of the array is a const generic, use

let (t, arr) = [1, 2].uncons();

Required Methods§

Source

fn uncons(self) -> (T, [T; { _ }])

Gives you the [head, tail @ ..]

let (t, arr) = b"abc".uncons();
Source

fn unsnoc(self) -> ([T; { _ }], T)

Gives you the [init @ .., last]

let (arr, t) = [0.1f32, 0.2, 0.3].unsnoc();
assert_eq!(t, 0.3);
Source

fn init(self) -> [T; { _ }]

Gives you a [init @ .., _] See also unsnoc.

let a = [1u64, 2, 3].init();
assert_eq!(a, [1, 2]);
Source

fn tail(self) -> [T; { _ }]

Gives you a [_, tail @ ..]. See also uncons.

let x = atools::range::<5>();
assert!(x.tail() == atools::range::<4>().map(|x| x + 1));
Source

fn last(self) -> T
where [(); { _ }]:,

Gives you a [_ @ .., last]. See also unsnoc.

Source

fn head(self) -> T
where [(); { _ }]:,

Gives you a [head, _ @ ..]. See also uncons.

Implementations on Foreign Types§

Source§

impl<T, const N: usize> Deconstruct<T, N> for [T; N]
where T:,

Source§

fn uncons(self) -> (T, [T; { _ }])

Source§

fn unsnoc(self) -> ([T; { _ }], T)

Source§

fn tail(self) -> [T; { _ }]
where T:,

Source§

fn init(self) -> [T; { _ }]

Source§

fn last(self) -> T
where [(); { _ }]:,

Source§

fn head(self) -> T
where [(); { _ }]:,

Implementors§