#map-set #ordinal #integer #enums

ordinal-map

Ordinal trait to map values to integers and efficient maps and sets for such types

10 releases

0.1.10 Nov 22, 2025
0.1.9 Aug 29, 2025
0.1.8 Jul 19, 2025
0.1.6 Jun 24, 2024

#134 in Data structures

Download history 26881/week @ 2025-10-27 30835/week @ 2025-11-03 31851/week @ 2025-11-10 33175/week @ 2025-11-17 25850/week @ 2025-11-24 29723/week @ 2025-12-01 39858/week @ 2025-12-08 30579/week @ 2025-12-15 22342/week @ 2025-12-22 22225/week @ 2025-12-29 29044/week @ 2026-01-05 30925/week @ 2026-01-12 50498/week @ 2026-01-19 42468/week @ 2026-01-26 50643/week @ 2026-02-02 73914/week @ 2026-02-09

221,685 downloads per month

MIT license

105KB
3K SLoC

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;
}

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;
}

Dependencies

~130–530KB
~13K SLoC