[][src]Trait index_vec::Idx

pub trait Idx: Copy + 'static + Ord + Debug + Hash {
    fn from_usize(idx: usize) -> Self;
fn index(self) -> usize; }

Represents a wrapped value convertable to and from a usize.

Generally you implement this via the define_index_type! macro, rather than manually implementing it.

Overflow

Idx impls are allowed to be smaller than usize, which means converting usize to an Idx implementation might have to handle overflow.

The way overflow is handled is up to the implementation of Idx, but it's generally panicing, unless it was turned off via the CHECK_MAX_INDEX_IF parameter in define_index_type.

This trait, as you can see, doesn't have a try_from_usize. The IndexVec type doesn't have additional functions exposing ways to handle index overflow. I'm open to adding these, but at the moment you should pick a size large enough that you won't hit problems, or verify the size cannot overflow elsewhere.

Required methods

fn from_usize(idx: usize) -> Self

Roughly equivalent to From

fn index(self) -> usize

Roughly equivalent to Into

Loading content...

Implementors

impl Idx for Idx32[src]

impl Idx for IdxSize[src]

impl Idx for u32[src]

impl Idx for usize[src]

Loading content...