Trait Indexable

Source
pub unsafe trait Indexable {
    type Iter: Iterator<Item = Self>;

    const SIZE: usize;
    const SET_SIZE: usize;

    // Required methods
    fn index(self) -> usize;
    fn iter() -> Self::Iter;
}
Expand description

Allows mapping from a type to an index

§Safety

This trait is unsafe because there are a few other requirements that need to be met:

  • The indexes of self need to be contiguous and need to be returned in order from iter()
  • Iter needs to return exactly N items (this is checked in debug mode)

Required Associated Constants§

Source

const SIZE: usize

The number of items or variants that this type can have.

Source

const SET_SIZE: usize

The number of bytes it will take to represent this type in a set.

§Safety

This must equal set_size(Self::SIZE)

Required Associated Types§

Source

type Iter: Iterator<Item = Self>

The type of Iterator that will be returned by Self::iter()

Required Methods§

Source

fn index(self) -> usize

Maps self to usize to know which value in the underling array to use

§Safety

This value can never be greater than Self::SIZE

All values in 0..SIZE must be returned by some variant of self.

Source

fn iter() -> Self::Iter

An Iterator over all valid values of self

§Safety

This iterator must yield exactly Self::SIZE items

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.

Implementations on Foreign Types§

Source§

impl Indexable for bool

Source§

const SIZE: usize = 2usize

Source§

const SET_SIZE: usize = 1usize

Source§

type Iter = IntoIter<bool, 2>

Source§

fn index(self) -> usize

Source§

fn iter() -> Self::Iter

Source§

impl Indexable for u8

Source§

const SIZE: usize = 256usize

Source§

const SET_SIZE: usize = 32usize

Source§

type Iter = RangeInclusive<u8>

Source§

fn index(self) -> usize

Source§

fn iter() -> Self::Iter

Source§

impl Indexable for u16

Source§

const SIZE: usize = 65_536usize

Source§

const SET_SIZE: usize = 8_192usize

Source§

type Iter = RangeInclusive<u16>

Source§

fn index(self) -> usize

Source§

fn iter() -> Self::Iter

Source§

impl<T, U> Indexable for (T, U)
where T: Indexable + Clone, U: Indexable,

Source§

impl<T, U, V> Indexable for (T, U, V)
where T: Indexable + Clone, U: Indexable + Clone, V: Indexable,

Source§

impl<T: Indexable> Indexable for Option<T>

Source§

const SIZE: usize

Source§

const SET_SIZE: usize

Source§

type Iter = Chain<Map<<T as Indexable>::Iter, fn(T) -> Option<T>>, Once<Option<T>>>

Source§

fn index(self) -> usize

Source§

fn iter() -> Self::Iter

Implementors§