Crate ordinal_map

Source
Expand description

The library provides Ordinal trait to map types to usize values, proc-macro to derive Ordinal trait for structs and enums, and map and set implementations that use these types as keys efficiently.

§Example

use ordinal_map::map::total::OrdinalTotalMap;
#[derive(ordinal_map::Ordinal)]
enum ErrorCategory {
    Network,
    Disk,
    Logic,
}

fn classify_error(error: &str) -> ErrorCategory {
    // ...
}

let mut error_counts: OrdinalTotalMap<ErrorCategory, u64> = OrdinalTotalMap::default();

for error in &errors {
    let category = classify_error(error);
    error_counts[&category] += 1;
}

Modules§

map
Constant time lookup map implementations where keys implement the Ordinal trait.
set
Constant time lookup set implementations where entries implement the Ordinal trait.

Structs§

OrdinalValues
Iterator over Ordinal values.

Traits§

Ordinal
Two-way map from a type to usize range from 0..ORDINAL_SIZE.

Derive Macros§

Ordinal
Derive Ordinal for structs or enums.