Skip to content

Commit 5218d0a

Browse files
feat: add support for v7 UUIDs (#101)
Title. Adds support for a v7 UUID method, but I didn't really _test_ this, but I can! --------- Co-authored-by: Rain <rain@oxide.computer>
1 parent c7b802f commit 5218d0a

File tree

6 files changed

+16
-5
lines changed

6 files changed

+16
-5
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ syn = "2.0.104"
3131
test-strategy = "0.4.1"
3232
trybuild = "1.0"
3333
typify = "0.4.2"
34-
uuid = { version = "1.17.0", default-features = false }
34+
uuid = { version = "1.18.1", default-features = false }
3535

3636
[workspace.lints.rust]
3737
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] }

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ help:
77
just --list
88

99
excluded_features_default := "internal-schemars08-tests internal-proptest1-tests"
10-
excluded_features_no_std := "schemars08 serde default std alloc v4 proptest1"
10+
excluded_features_no_std := "schemars08 serde default std alloc v4 v7 proptest1"
1111

1212
# Run `cargo hack --feature-powerset` on crates
1313
powerset *args:

crates/newtype-uuid-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ serde_tokenstream.workspace = true
2222
syn = { workspace = true, features = ["full"] }
2323

2424
[dev-dependencies]
25-
newtype-uuid = { workspace = true, features = ["v4"] }
25+
newtype-uuid = { workspace = true, features = ["v4", "v7"] }
2626
serde = { workspace = true, features = ["derive"] }
2727
static_assertions.workspace = true
2828

crates/newtype-uuid/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ default = ["uuid/default", "std"]
3434
std = ["alloc", "uuid/std"]
3535
alloc = []
3636
v4 = ["uuid/v4"]
37+
v7 = ["uuid/v7"]
3738
serde = ["dep:serde", "uuid/serde"]
3839
schemars08 = ["dep:schemars", "dep:serde_json", "std"]
3940
proptest1 = ["dep:proptest"]

crates/newtype-uuid/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ use core::{
166166
marker::PhantomData,
167167
str::FromStr,
168168
};
169+
#[cfg(feature = "v7")]
170+
pub use uuid::Timestamp;
169171
use uuid::{Uuid, Version};
170172

171173
/// A UUID with type-level information about what it's used for.
@@ -302,6 +304,14 @@ impl<T: TypedUuidKind> TypedUuid<T> {
302304
Self::from_untyped_uuid(Uuid::new_v4())
303305
}
304306

307+
/// Creates a new, random UUID v7 of this type.
308+
#[inline]
309+
#[cfg(feature = "v7")]
310+
#[must_use]
311+
pub fn new_v7(ts: uuid::Timestamp) -> Self {
312+
Self::from_untyped_uuid(Uuid::new_v7(ts))
313+
}
314+
305315
/// Returns the version number of the UUID.
306316
///
307317
/// This represents the algorithm used to generate the value.

0 commit comments

Comments
 (0)