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

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 DISABLE_MAX_INDEX_CHECK option in define_index_type!. If you need more subtle handling than this, then you’re on your own (or, well, either handle it earlier, or pick a bigger index type).

Note: I’m open for suggestions on how to handle this case, but do not want the typical cases (E.g. Idx is a newtyped usize or u32), to become more complex.

Required Methods

Construct an Index from a usize. This is equivalent to From.

Note that this will panic if idx does not fit (unless checking has been disabled, as mentioned above). Also note that Idx implementations are free to define what “fit” means as they desire.

Get the underlying index. This is equivalent to Into

Implementations on Foreign Types

Implementors