Crates.io | slid |
lib.rs | slid |
version | 0.2.0 |
source | src |
created_at | 2022-12-10 20:52:49.603226 |
updated_at | 2022-12-10 23:51:10.276352 |
description | Simple labeled IDs |
homepage | |
repository | https://gitlab.com/dawn_app/slid |
max_upload_size | |
id | 734015 |
size | 8,845 |
Simple IDs with associated type labels.
use slid::Id;
struct User;
let player_a = Id::<User>::new_random();
let player_b = Id::<User>::new_random();
// For all practical purposes, we can assume that 2 random IDs will be unique and different
assert_ne!(player_a, player_b);
// The label generic helps avoid mixups:
struct Product;
fn delete_product(id: Id<Product>) {}
// Doesn't compile, because Id<User> and Id<Player> are different
// delete_product(player_a);
// But you can explicitly cast the label if needed:
delete_product(player_a.cast_label());
Note: this library does not attempt conform to any UUID standards. Random IDs are plain simple random. If you want the standardized UUIDs, check out uuid