uuid icon indicating copy to clipboard operation
uuid copied to clipboard

Generate v5 & v3 UUIDs from Values that Implement `Hash`

Open azdle opened this issue 3 years ago • 0 comments

Motivation I've got a few different things that are shaped like https://doc.rust-lang.org/std/thread/struct.ThreadId.html, opaque identifiers that wrap a u64, that I'm using to generate reproducible unique IDs by name-spacing them with new_v5. These all implement Hash, it would be nice if I could just hand them to new_v5 or a 5v_from_hash or something.

Solution I believe new_v5 and new_v3 could be changed from their current

fn new_v5(namespace: &Uuid, name: &[u8]) -> Uuid

to something like

fn new_v5<H: Hash>(namespace: &Uuid, name: &H) -> Uuid

Alternatives I'm unsure if that could be a breaking change with how coercion are handled. If it is, new separate functions could be created instead.

Is it blocking? Nope, I have a gross thing to extract the raw IDs for now, but it would be nice to not have to do that.

azdle avatar Sep 21 '22 16:09 azdle