KeyValue

Trait KeyValue 

Source
pub trait KeyValue<'a> {
    type K: Ord;
    type V;

    // Required methods
    fn key(&'a self) -> Self::K;
    fn value(&'a self) -> Self::V;
}
Expand description

Trait that T must implement to be able to work with MapOfIndexes of T.

Can be implemented on your own custom structs. KeyValue::K represents the key (index) of the pair, while KeyValue::V is the value.

KeyValue is already implemented for all 2-tuples, the first element being considered as the key.

§Examples

use map_of_indexes::KeyValue;

let tuple: (String, i64) = ("Key".to_string(), 123);
// In this blanket implementation, both functions return a reference
assert_eq!(tuple.key(), &"Key");
assert_eq!(tuple.value(), &123i64);

If you need a very compact representation, see CombinedKeyValue, which stores both the key and the key on a uint of a given size.

Required Associated Types§

Source

type K: Ord

Source

type V

Required Methods§

Source

fn key(&'a self) -> Self::K

Source

fn value(&'a self) -> Self::V

Implementations on Foreign Types§

Source§

impl<'a, KEY, VALUE> KeyValue<'a> for (KEY, VALUE)
where KEY: 'a + Ord, VALUE: 'a,

Source§

type K = &'a KEY

Source§

type V = &'a VALUE

Source§

fn key(&'a self) -> Self::K

Source§

fn value(&'a self) -> Self::V

Implementors§

Source§

impl<'a, T: TryFrom<u128> + Ord + Copy, const KEY_NB_BITS: u8, const VALUE_NB_BITS: u8> KeyValue<'a> for CombinedKeyValue<T, KEY_NB_BITS, VALUE_NB_BITS>
where u128: From<T>, <T as TryFrom<u128>>::Error: Debug,

Source§

type K = T

Source§

type V = T