Trait IndexType

Source
pub trait IndexType:
    Copy
    + Display
    + Sized
    + Eq
    + Ord {
    const MAX: Self;

    // Required methods
    fn get(self) -> usize;
    fn new(element_num: usize) -> Result<Self, &'static str>;

    // Provided method
    fn defined(self) -> bool { ... }
}
Expand description

Trait for index types: used in the inner representation of IntervalMap and IntervalSet.

Implemented for u8, u16, u32 and u64, u32 is used by default (DefaultIx).

IntervalMap or IntervalSet can store up to Ix::MAX - 1 elements (for example IntervalMap<_, _, u8> can store up to 255 items).

Using smaller index types saves memory and slightly reduces running time.

Required Associated Constants§

Source

const MAX: Self

Undefined index. There can be no indices higher than MAX.

Required Methods§

Source

fn get(self) -> usize

Converts index into usize.

Source

fn new(element_num: usize) -> Result<Self, &'static str>

Creates a new index. Returns error if the elemen_num is too big.

Provided Methods§

Source

fn defined(self) -> bool

Returns true if the index is defined.

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 IndexType for u8

Source§

const MAX: Self = 255u8

Source§

fn get(self) -> usize

Source§

fn new(element_num: usize) -> Result<Self, &'static str>

Source§

impl IndexType for u16

Source§

const MAX: Self = 65_535u16

Source§

fn get(self) -> usize

Source§

fn new(element_num: usize) -> Result<Self, &'static str>

Source§

impl IndexType for u32

Source§

const MAX: Self = 4_294_967_295u32

Source§

fn get(self) -> usize

Source§

fn new(element_num: usize) -> Result<Self, &'static str>

Source§

impl IndexType for u64

Source§

const MAX: Self = 18_446_744_073_709_551_615u64

Source§

fn get(self) -> usize

Source§

fn new(element_num: usize) -> Result<Self, &'static str>

Implementors§