ordinal-map

Crates.ioordinal-map
lib.rsordinal-map
version0.1.6
sourcesrc
created_at2024-06-24 00:41:28.601648
updated_at2024-06-24 01:51:13.822503
descriptionOrdinal trait to map values to integers and efficient maps and sets for such types
homepage
repositoryhttps://github.com/stepancheg/ordinal-map
max_upload_size
id1281545
size96,122
Stepan Koltsov (stepancheg)

documentation

https://docs.rs/ordinal-map

README

Ordinal types and collections

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;
}
Commit count: 65

cargo fmt