https://github.com/stepancheg/ordinal-map
Map types to integers
https://github.com/stepancheg/ordinal-map
Last synced: about 1 year ago
JSON representation
Map types to integers
- Host: GitHub
- URL: https://github.com/stepancheg/ordinal-map
- Owner: stepancheg
- Created: 2024-06-22T21:28:09.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-24T01:50:57.000Z (almost 2 years ago)
- Last Synced: 2025-03-25T04:28:48.546Z (about 1 year ago)
- Language: Rust
- Size: 86.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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
```rust
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 = OrdinalTotalMap::default();
for error in &errors {
let category = classify_error(error);
error_counts[category] += 1;
}
```