-
Notifications
You must be signed in to change notification settings - Fork 223
Description
Motivation
The UUID Crate has grow organically over the last 5 years. It's seen many new features, and groups of features added, and new uuid version support has been added, where convenient. The Rust ecosystem has evolved significantly in that time. The implementations in the crate have sort of evolved in different directions, there is the Builder, which has functions which are general, and it has functions which are specific to a single UUID version (without mentioning that version's name, see ::from_random_bytes)).
There are about 15 features in this crate (if you include the newest versions). IMO, that number should be closer to 4.
As a result of its growths and offshoots in various areas, the crate is a bit of a mess, with many inconsistencies and some characteristics that make it look a bit dated.
Solution
I propose we refactor the crate in preparation for a new major release.
The basic idea would be this:
- We remove all version-specific features, and provide 3 top-level, unified APIs. Both APIs can build any Uuid version, which tools they have to build said versions is up to the included features. The top level APIs would be:
- A high-level builder API that can build all version
- A lower-level, module-based API which exposes consistent functions for every version of uuid. There would also be version-specific functions where needed. Where each implementation is in its own module, e.g.
uuid::v1::new(...) - The Uuid struct, which would not know how to construct itself directly, outside of parsing/converting Uuids in other formats.
- The only Cargo features would be ones that are specific to target platform restrictions (e.g. wasm, embedded, nostd, fast-random vs /dev/random etc)
- We put all stateful and random generation things inside a GeneratorContext (or whatever we want to name it) This way, if people wish to use their own RNGs or clock-sequences, or whatever, it can be tucked neatly away inside that.
- Timestamp would stay, but would be abstracted away by the high-level functions, people shouldn't have to generate their own time if they don't want to. (if they disable std, then they would have to bring their own time functions and construct their own timestamps)
If people are OK with this basic arrangement, then I will start working on an RFC.