Trait Indexed

Source
pub trait Indexed {
    const SIZE: usize;

    // Required methods
    fn index(&self) -> usize;
    fn from_index(index: usize) -> Option<Self>
       where Self: Sized;
}
Expand description

An indexed set of finitely many possibilities.

Can be implemented automatically for enum types with no internal data using #[derive(Indexed)].

use relearn::spaces::Indexed;

#[derive(Indexed)]
enum Foo {
    A,
    B,
}

assert_eq!(Foo::SIZE, 2);
assert_eq!(Foo::B.index(), 1);

Required Associated Constants§

Source

const SIZE: usize

The number of possible values this type can represent.

Required Methods§

Source

fn index(&self) -> usize

The index of this element.

Source

fn from_index(index: usize) -> Option<Self>
where Self: Sized,

Construct from an index.

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 Indexed for bool

Source§

const SIZE: usize = 2usize

Source§

fn index(&self) -> usize

Source§

fn from_index(index: usize) -> Option<Self>

Implementors§

Source§

impl Indexed for CellView

Source§

const SIZE: usize = 4usize

Source§

impl Indexed for Move

Source§

const SIZE: usize = 5usize