4 releases (stable)

new 1.0.2 Mar 11, 2025
0.1.0 Mar 11, 2025

#1 in #assign

Download history 225/week @ 2025-03-07

225 downloads per month

Apache-2.0

14KB
147 lines

Itemizer

License

Itemizer is a data structure that maps items to unique integer IDs. It is used to convert items into unique IDs, and back again.

The Itemizer is generic over the type of the item, so it can be used with any type that implements the Eq, Hash, Ord, and Clone traits.

When calling id_of on an itemizer, it assigns an index, wrapped in an Item struct which represents this value. Using value_of, the original value can be retrieved.

Example


let mut itemizer = Itemizer::new();
let item1 = itemizer.id_of(&"item1".to_string());
let item2 = itemizer.id_of(&"item2".to_string());

assert_eq!(itemizer.value_of(&item1), &"item1".to_string());
assert_eq!(itemizer.value_of(&item2), &"item2".to_string());


lib.rs:

Itemizer is a data structure that maps items to unique integer IDs. It is used to convert items into unique IDs, and back again.

The Itemizer is generic over the type of the item, so it can be used with any type that implements the Eq, Hash, Ord, and Clone traits.

When calling id_of on an itemizer, it assigns an index, wrapped in an Item struct which represents this value. Using value_of, the original value can be retrieved.

use itemizer::Itemizer;

let mut itemizer = Itemizer::new();
let item1 = itemizer.id_of(&"item1".to_string());
let item2 = itemizer.id_of(&"item2".to_string());

assert_eq!(itemizer.value_of(&item1), &"item1".to_string());
assert_eq!(itemizer.value_of(&item2), &"item2".to_string());

Dependencies

~17KB