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§
Required Methods§
Sourcefn from_index(index: usize) -> Option<Self>where
Self: Sized,
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.