Trait more_collections::vec_map::IndexKey

source ·
pub trait IndexKey: Copy {
    // Required methods
    fn as_index(&self) -> usize;
    fn from_index(index: usize) -> Self;
}
Expand description

A key that can be used in a map without needing a hasher.

There needs to be a 1:1 correspondence between IndexKey and it’s index. Typically this is used with a newtype. A blanket implementation exists for types that implement From<usize>, Into<usize>, and Copy. By using a crate such as derive_more these traits can be derived.

Required Methods§

source

fn as_index(&self) -> usize

Returns the unique index that this key is associated with.

source

fn from_index(index: usize) -> Self

Converts the index back to the key.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> IndexKey for T
where T: From<usize> + Into<usize> + Copy,