refactors Timestamp, Context and ClockSequence, and adds UUIDS v6, v7, v8 #611

Merged
rrichardson merged 22 commits from six-seven-eight into main 2022-09-01 18:38:08 -05:00
rrichardson commented 2022-08-16 19:25:25 -05:00 (Migrated from github.com)

I'm submitting a feature

Description

This addresses all requested features in #523

Adds v6, v7 and v8 features and modules.
It also adds a Timestamp::now() which does what you might expect and uses std::time::SystemTime.
I added some basic tests for each, but they could certainly use more tests and more eyes.

Breaking changes

This refactors Timestamp to make it more generally applicable to all (time based) UUIDs.
It also breaks context/sequence out of Timestamp, since that only applies to v1 and v6.
This changes the API for v1 and v6, to require a Context to be supplied at creation.
Updates the crate to Edition 2021

Dependency Changes

Removes a dependency on atomic and instead uses std::sync::atomic since it now supports the necessary types.

Related Issue(s)

#523

**I'm submitting a feature** # Description This addresses all requested features in #523 Adds v6, v7 and v8 features and modules. It also adds a Timestamp::now() which does what you might expect and uses std::time::SystemTime. I added some basic tests for each, but they could certainly use more tests and more eyes. ## Breaking changes This refactors Timestamp to make it more generally applicable to all (time based) UUIDs. It also breaks context/sequence out of Timestamp, since that only applies to v1 and v6. This changes the API for v1 and v6, to require a Context to be supplied at creation. Updates the crate to Edition 2021 ## Dependency Changes Removes a dependency on atomic and instead uses std::sync::atomic since it now supports the necessary types. # Related Issue(s) #523
robjtede commented 2022-08-17 07:25:50 -05:00 (Migrated from github.com)

Just want to say from a lib maintainer's perspective, there's basically no good reason that such a widely used crate should need to get bumped to edition = 2021. It hurts compatibility for folks on earlier compilers/editions far more than it helps maintainability (compared to 2015->2018 shift).

Just want to say from a lib maintainer's perspective, there's basically no good reason that such a widely used crate should need to get bumped to `edition = 2021`. It hurts compatibility for folks on earlier compilers/editions far more than it helps maintainability (compared to 2015->2018 shift).
rrichardson commented 2022-08-17 09:30:26 -05:00 (Migrated from github.com)

@robjtede - Thanks for the input. The shift to 2021 really wasn't much more than changing the value in the Cargo.toml. What about it hurts compatibility?

@robjtede - Thanks for the input. The shift to 2021 really wasn't much more than changing the value in the Cargo.toml. What about it hurts compatibility?
mqudsi commented 2022-08-17 14:27:22 -05:00 (Migrated from github.com)

The msrv for edition 2021 is 1.56.0; main is still targeting an msrv of 1.46.0.

The msrv for edition 2021 is 1.56.0; `main` is still targeting an msrv of 1.46.0.
KodrAus (Migrated from github.com) reviewed 2022-08-21 20:02:58 -05:00
KodrAus (Migrated from github.com) left a comment

Thanks for working on this @rrichardson! 🙇

We can't make breaking changes to UUID's API now that it's stable, so I think our best option with the timestamp is to either:

  1. Interpret the subseconds field as a counter in v1/v6 UUIDs and as extra precision in v7/v8
  2. Make the timestamp an enum that's either a v1/v6 or v7/v8 timestamp.

Neither of these are as ideal as your refactoring, but I think we need to work within the API we've got.

Thanks for working on this @rrichardson! :bow: We can't make breaking changes to UUID's API now that it's stable, so I think our best option with the timestamp is to either: 1. Interpret the subseconds field as a counter in v1/v6 UUIDs and as extra precision in v7/v8 2. Make the timestamp an enum that's either a v1/v6 or v7/v8 timestamp. Neither of these are as ideal as your refactoring, but I think we need to work within the API we've got.
@ -0,0 +72,4 @@
/// NOTE: This function will panic if the current system time is earlier than
/// the Unix Epoch of 1970-01-01 00:00:00 So please use caution when time travelling.
#[cfg(all(feature = "std", not(any(feature = "v1", feature = "v6"))))]
pub fn now() -> Self {
KodrAus (Migrated from github.com) commented 2022-08-21 19:59:15 -05:00

This is a great change 👍

This is a great change :+1:
KodrAus (Migrated from github.com) commented 2022-08-21 19:57:10 -05:00

We can't really make breaking changes to UUID, so while this change is clearer than the current API I think we'll need to stick with what we've got.

We can't really make breaking changes to UUID, so while this change is clearer than the current API I think we'll need to stick with what we've got.
rrichardson (Migrated from github.com) reviewed 2022-08-22 11:49:43 -05:00
rrichardson (Migrated from github.com) commented 2022-08-22 11:49:43 -05:00

OK.. I'll make this PR conform to the existing Library/Tests. I will make a follow up PR with an RFC for my proposed API refactorings re: https://github.com/uuid-rs/uuid/issues/612

OK.. I'll make this PR conform to the existing Library/Tests. I will make a follow up PR with an RFC for my proposed API refactorings re: https://github.com/uuid-rs/uuid/issues/612
rrichardson commented 2022-08-22 11:51:07 -05:00 (Migrated from github.com)

@KodrAus - Do you know any ways that we can work around the fact that 2 of the CI jobs fail when running the powerset of features (runs the container out of space) I'm not a Github Actions wizard. It seems 15 features pushes it over the failing point.

@KodrAus - Do you know any ways that we can work around the fact that 2 of the CI jobs fail when running the powerset of features (runs the container out of space) I'm not a Github Actions wizard. It seems 15 features pushes it over the failing point.
KodrAus commented 2022-08-22 16:42:07 -05:00 (Migrated from github.com)

@rrichardson I'll send a PR through that rejigs that part of CI a bit. The main thing we want to ensure is that each feature works independently, and that they all work together. I'll give you a ping when that's up.

@rrichardson I'll send a PR through that rejigs that part of CI a bit. The main thing we want to ensure is that each feature works independently, and that they all work together. I'll give you a ping when that's up.
rrichardson commented 2022-08-22 20:00:37 -05:00 (Migrated from github.com)

@KodrAus - Ok.. This should be compatible with the original API. Note, this API requires some silly hoop-jumping for any versions that use a timestamp but not a counter (e.g. v7 https://github.com/rrichardson/uuid/blob/six-seven-eight/src/v7.rs#L53-L61)

@KodrAus - Ok.. This should be compatible with the original API. Note, this API requires some silly hoop-jumping for any versions that use a timestamp but not a counter (e.g. v7 https://github.com/rrichardson/uuid/blob/six-seven-eight/src/v7.rs#L53-L61)
rrichardson commented 2022-08-25 17:16:14 -05:00 (Migrated from github.com)

All checks have passed! 🎊 🍾

All checks have passed! 🎊 🍾
KodrAus (Migrated from github.com) reviewed 2022-08-29 04:19:12 -05:00
KodrAus (Migrated from github.com) left a comment

This is awesome work! Thanks for putting it together, and for sticking through our current API constraints 🙇 I just had a few minor comments.

This is awesome work! Thanks for putting it together, and for sticking through our current API constraints :bow: I just had a few minor comments.
KodrAus (Migrated from github.com) commented 2022-08-29 04:08:42 -05:00

Was making this field public intentional?

Was making this field public intentional?
@ -0,0 +1,233 @@
/// Contains the `Timestamp` struct and `ClockSequence` traits
KodrAus (Migrated from github.com) commented 2022-08-29 04:16:54 -05:00

I think this can happen on systems with drifting clocks, maybe more likely to be observed on Windows since its epoch is earlier than the Unix one?

I don't have a great alternative for what we should do, besides documenting that this method will panic if the system time is set earlier than the Unix epoch.

I think this can happen on systems with drifting clocks, maybe more likely to be observed on Windows since its epoch is earlier than the Unix one? I don't have a great alternative for what we should do, besides documenting that this method will panic if the system time is set earlier than the Unix epoch.
rrichardson (Migrated from github.com) reviewed 2022-08-29 13:55:46 -05:00
@ -0,0 +1,233 @@
/// Contains the `Timestamp` struct and `ClockSequence` traits
rrichardson (Migrated from github.com) commented 2022-08-29 13:55:46 -05:00

I think that clock drift shouldn't be a problem. The Result returned by SystemTime::elapsed() is an error if self's time happens after now. In this case, it is checking that that the current system time is later than Jan 1st, 1970.
I'll update the documentation and the message accordingly.

I think that clock drift shouldn't be a problem. The Result returned by `SystemTime::elapsed()` is an error if self's time happens **after** now. In this case, it is checking that that the current system time is later than Jan 1st, 1970. I'll update the documentation and the message accordingly.
KodrAus (Migrated from github.com) reviewed 2022-08-29 16:43:43 -05:00
@ -0,0 +1,233 @@
/// Contains the `Timestamp` struct and `ClockSequence` traits
KodrAus (Migrated from github.com) commented 2022-08-29 16:43:43 -05:00

Yeh, so less drifting clocks, and maybe more likely misconfigured Windows systems, where their epoch is some much earlier date than the Unix one 🤔

Yeh, so less drifting clocks, and maybe more likely misconfigured Windows systems, where their epoch is some much earlier date than the Unix one 🤔
rrichardson (Migrated from github.com) reviewed 2022-08-30 11:05:43 -05:00
rrichardson (Migrated from github.com) commented 2022-08-30 11:05:42 -05:00

Yeah.. this was necessary due to moving modules around. actually.. it could probably be pub (crate)

Yeah.. this was necessary due to moving modules around. actually.. it could probably be pub (crate)
rrichardson (Migrated from github.com) reviewed 2022-08-30 11:09:18 -05:00
rrichardson (Migrated from github.com) commented 2022-08-30 11:09:18 -05:00

ok.. I just checked and maybe it's not necessary. Removed.

ok.. I just checked and maybe it's not necessary. Removed.
0xpr03 (Migrated from github.com) reviewed 2022-08-31 09:09:35 -05:00
@ -0,0 +1,167 @@
//! The implementation for Version 1 UUIDs.
0xpr03 (Migrated from github.com) commented 2022-08-31 09:09:35 -05:00

I think you meant to say v6 feature

//! Note that you need to enable the `v6` Cargo feature
I think you meant to say `v6` feature ```suggestion //! Note that you need to enable the `v6` Cargo feature ```
0xpr03 (Migrated from github.com) reviewed 2022-08-31 09:10:10 -05:00
@ -0,0 +1,91 @@
//! The implementation for Version 1 UUIDs.
0xpr03 (Migrated from github.com) commented 2022-08-31 09:10:10 -05:00

Same here

//! Note that you need to enable the `v7` Cargo feature
Same here ```suggestion //! Note that you need to enable the `v7` Cargo feature ```
rrichardson (Migrated from github.com) reviewed 2022-08-31 13:33:04 -05:00
@ -0,0 +1,167 @@
//! The implementation for Version 1 UUIDs.
rrichardson (Migrated from github.com) commented 2022-08-31 13:33:04 -05:00

Righto. Thanks!

Righto. Thanks!
rrichardson commented 2022-08-31 14:36:08 -05:00 (Migrated from github.com)

BTW: Arbitrary just bumped their patch version which added the use of array::from_fn which was just stabilized in Rust 1.63. So some of the CI jobs failed because of this. I've locked Arbitrary to the prior version (1.1.3) until we can bump all CI workers to 1.63

BTW: Arbitrary just bumped their patch version which added the use of array::from_fn which was just stabilized in Rust 1.63. So some of the CI jobs failed because of this. I've locked Arbitrary to the prior version (1.1.3) until we can bump all CI workers to 1.63
KodrAus commented 2022-09-01 18:38:03 -05:00 (Migrated from github.com)

Thanks for working through this @rrichardson! This is an amazing effort 🙇

Thanks for working through this @rrichardson! This is an amazing effort :bow:
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-uuid-rs/uuid!611
No description provided.