Trait IntoIndex

Source
pub trait IntoIndex<const DIM: usize> {
    // Required method
    fn into_index(self) -> [usize; DIM];
}
Expand description

A convenience trait to allow accepting and interchangeably using indices as arrays or tuples.

A struct implementing IntoIndex<DIM> can be converted into and index represented as [usize; DIM], such as:

  • usize, (usize), [usize; 1] implement IntoIndex<1>, and hence, can be converted into [usize; 1];
  • (usize, usize), [usize; 2] implement IntoIndex<2>, and hence, can be converted into [usize; 2];

Required Methods§

Source

fn into_index(self) -> [usize; DIM]

Converts the value into an index represented as [usize; DIM].

§Example
use orx_funvec::*;

let i = 2;
let index = i.into_index();
assert_eq!(index, [2]);

let ij = (3, 4);
let index = ij.into_index();
assert_eq!(index, [3, 4]);

Implementations on Foreign Types§

Source§

impl IntoIndex<DIM> for (usize, usize)

Source§

fn into_index(self) -> [usize; 2]

Source§

impl IntoIndex<DIM> for (usize, usize, usize)

Source§

fn into_index(self) -> [usize; 3]

Source§

impl IntoIndex<DIM> for (usize, usize, usize, usize)

Source§

fn into_index(self) -> [usize; 4]

Source§

impl IntoIndex<DIM> for usize

Source§

fn into_index(self) -> [usize; 1]

Source§

impl<const DIM: usize> IntoIndex<DIM> for [usize; DIM]

Implementors§