Stebalien / snowflake

A high-performance unique-id library for rust
Apache License 2.0
75 stars 9 forks source link

Problem: sometimes, ProcessUniqueId internals access is needed #7

Closed yrashk closed 7 years ago

yrashk commented 7 years ago

For example, for serialization

Solution: expose fields as public ones

Stebalien commented 7 years ago

Hm, I'll have to think about this. Serializing ProcessUniqueIDs can be dangerous given that they're only guaranteed to be unique within a process for the life of the process. However, to be useful for RPC/inter process communication, they need to be serializable.

One solution would be to map the prefix to a UUID as needed:

Although I guess they would no longer be "process unique".

If I don't get back to you within a few days, please bug me.

yrashk commented 7 years ago

Actually, in my case them being process unique is fine, they only serve as random identifiers that are always handled by the same process (which has a map associating these ids with resources) https://github.com/PumpkinDB/PumpkinDB/blob/master/src/script/storage.rs#L60

Stebalien commented 7 years ago

What's your use-case for serializing? I'd prefer to, e.g., implement Serialize using serde instead of exposing internals directly so I remain free to change them (for example, to implement #3).

I am worried that users will accidentally abuse serialization (e.g., derive Serialize for a struct that contains a ProcessUniqueID and persist it somewhere); However, I guess that's probably just paranoid.

yrashk commented 7 years ago

Steven, sorry for this huge delay. Serializing without exposing details would be totally cool for me. All I need is a compact binary representation of the ID — don't care what's inside.

Stebalien commented 7 years ago

Sorry for the even longer delay...

I've merged #8 which implements serialization through serde.