Skip to content

Commit 9a1fc4a

Browse files
committed
feat: support multiple time crates
1 parent 3170cda commit 9a1fc4a

8 files changed

Lines changed: 493 additions & 139 deletions

File tree

.github/workflows/CI.yml

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,37 @@
11
name: CI
2-
32
on:
43
push:
54
branches:
6-
- main
5+
- main
76
pull_request: {}
8-
97
jobs:
10-
check:
11-
# Run `cargo check` first to ensure that the pushed code at least compiles.
8+
lint:
129
runs-on: ubuntu-latest
1310
steps:
14-
- uses: actions/checkout@master
15-
- uses: actions-rs/toolchain@v1
16-
with:
17-
toolchain: nightly
18-
override: true
19-
profile: minimal
20-
components: clippy, rustfmt
21-
- uses: Swatinem/rust-cache@v1
22-
- name: Check
23-
uses: actions-rs/cargo@v1
24-
with:
25-
command: clippy
26-
args: --all --all-targets --all-features
27-
- name: rustfmt
28-
uses: actions-rs/cargo@v1
29-
with:
30-
command: fmt
31-
args: --all -- --check
32-
11+
- uses: actions/checkout@v6
12+
- uses: dtolnay/rust-toolchain@master
13+
with:
14+
toolchain: nightly
15+
components: clippy, rustfmt
16+
- uses: Swatinem/rust-cache@v1
17+
- name: clippy
18+
run: cargo clippy --all --all-targets --all-features
19+
- name: rustfmt
20+
run: cargo fmt --all -- --check
3321
test-versions:
34-
needs: check
3522
runs-on: ubuntu-latest
3623
strategy:
3724
matrix:
3825
rust: [stable, beta]
3926
steps:
40-
- uses: actions/checkout@master
41-
- uses: actions-rs/toolchain@v1
42-
with:
43-
toolchain: ${{ matrix.rust }}
44-
override: true
45-
profile: minimal
46-
- uses: Swatinem/rust-cache@v1
47-
- name: Run tests
48-
uses: actions-rs/cargo@v1
49-
with:
50-
command: test
51-
args: --all --all-features --all-targets
52-
- name: Run doc tests
53-
uses: actions-rs/cargo@v1
54-
with:
55-
command: test
56-
args: --doc
57-
58-
# deny-check:
59-
# name: cargo-deny check
60-
# runs-on: ubuntu-latest
61-
# continue-on-error: ${{ matrix.checks == 'advisories' }}
62-
# strategy:
63-
# matrix:
64-
# checks:
65-
# - advisories
66-
# - bans licenses sources
67-
# steps:
68-
# - uses: actions/checkout@v2
69-
# - uses: EmbarkStudios/cargo-deny-action@v1
70-
# with:
71-
# command: check ${{ matrix.checks }}
72-
# arguments: --all-features --manifest-path axum/Cargo.toml
27+
- uses: actions/checkout@v6
28+
- uses: dtolnay/rust-toolchain@master
29+
with:
30+
toolchain: ${{ matrix.rust }}
31+
- uses: Swatinem/rust-cache@v2
32+
- name: Run tests (all features)
33+
run: cargo test --all --all-features --all-targets
34+
- name: Run tests (no features)
35+
run: cargo test --all --no-default-features --all-targets
36+
- name: Run doc tests
37+
run: cargo test --doc

.github/workflows/release.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
name: Release
2-
32
env:
43
CARGO_TERM_COLOR: always
5-
64
on:
75
push:
86
tags:
97
- 'v*'
10-
118
jobs:
129
build:
1310
runs-on: ubuntu-latest
1411
environment: release
15-
1612
permissions:
1713
id-token: write
18-
1914
steps:
2015
- uses: actions/checkout@v6
21-
2216
- uses: dtolnay/rust-toolchain@stable
23-
2417
- uses: Swatinem/rust-cache@v2
2518
# only restore cache for faster publishing, don't save back results
26-
save-if: false
27-
19+
save-if: "false"
2820
- uses: rust-lang/crates-io-auth-action@v1
2921
id: auth
30-
3122
- name: Publish
3223
env:
3324
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

.github/workflows/security.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
name: Security
2-
32
on:
43
push:
54
branches:
6-
- main
7-
paths:
8-
- '**/Cargo.toml'
9-
- '**/Cargo.lock'
5+
- main
106
pull_request:
117
paths:
128
- '**/Cargo.toml'
139
- '**/Cargo.lock'
14-
10+
- 'deny.toml'
1511
jobs:
16-
security_audit:
12+
cargo-deny:
13+
name: cargo-deny check
1714
runs-on: ubuntu-latest
1815
steps:
19-
- uses: actions/checkout@v1
20-
- uses: actions-rs/audit-check@v1
16+
- uses: actions/checkout@v6
17+
- uses: EmbarkStudios/cargo-deny-action@v2
2118
with:
22-
token: ${{ secrets.GITHUB_TOKEN }}
19+
manifest-path: Cargo.toml

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "svix-ksuid"
33
version = "0.8.0"
44
authors = ["Svix Inc. <oss@svix.com>"]
5-
edition = "2021"
5+
edition = "2024"
66
description="A pure Rust and fully tested KSUID implementation"
77
homepage="https://www.svix.com"
88
repository="https://github.com/svix/rust-ksuid"
@@ -15,15 +15,20 @@ categories = ["data-structures", "concurrency", "database", "encoding"]
1515
maintenance = {status="actively-developed"}
1616

1717
[features]
18-
# Include nothing by default
19-
default = []
18+
# Include `time` by default, to match old behavior
19+
default = ["time03"]
2020
serde = ["dep:serde"]
21+
jiff02 = ["dep:jiff"]
22+
time03 = ["dep:time"]
23+
chrono04 = ["dep:chrono"]
2124

2225
[dependencies]
2326
base-encode = "^0.3.1"
2427
byteorder = "^1.4.3"
2528
getrandom = "0.4.2"
26-
time = "0.3.7"
29+
time = { version = "0.3.47", optional = true }
30+
chrono = { version = "0.4", optional = true }
31+
jiff = { version = "0.2", optional = true }
2732
serde = { version = "^1.0.145", optional = true, features = ["derive"] }
2833

2934
[dev-dependencies]

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ For the Python version, please check out https://github.com/svix/python-ksuid
2424

2525
## What is a ksuid?
2626

27-
A ksuid is a K sorted UID. In other words, a KSUID also stores a date component, so that ksuids can be approximately
28-
sorted based on the time they were created.
27+
A ksuid is a K sorted UID. In other words, a KSUID also stores a date component, so that ksuids can be approximately
28+
sorted based on the time they were created.
2929

3030
Read more [here](https://segment.com/blog/a-brief-history-of-the-uuid/).
3131

@@ -41,7 +41,7 @@ svix-ksuid = "^0.6.0"
4141
```rust
4242
use svix_ksuid::*;
4343

44-
let ksuid = Ksuid::new(None, None);
44+
let ksuid = Ksuid::now(None);
4545
println!("{}", ksuid.to_string());
4646
// 1srOrx2ZWZBpBUvZwXKQmoEYga2
4747
```
@@ -57,19 +57,22 @@ The code too is fully compatible:
5757
```rust
5858
use svix_ksuid::*;
5959

60-
let ksuid = KsuidMs::new(None, None);
60+
let ksuid = KsuidMs::now(None);
6161
```
6262

6363
And they both implement the same `KsuidLike` trait.
6464

6565
### Opt-in features
6666
* `serde` - adds the ability to serialize and deserialize `Ksuid` and `KsuidMs`
6767
using serde.
68+
* `time03` - accept timestamps as the `time::OffsetDateTime` type from the [time](https://crates.io/crates/time) (0.3.x) crate &ndash; this feature is enabled by default, for compatibility with 0.8.x and older verisons
69+
* `chrono04` - accept timestamps as the `chrono::DateTime<chrono::Utc>` type from the [chrono](https://crates.io/crates/chrono) (0.4.x) crate
70+
* `jiff02` - accept timestamps as the `jiff::Timestamp` type from the [jiff](https://crates.io/crates/jiff) (0.2.x) crate
6871

6972
Make sure to enable like this:
7073
```toml
7174
[dependencies]
72-
svix-ksuid = { version = "^0.6.0", features = ["serde"] }
75+
svix-ksuid = { version = "^0.6.0", features = ["serde", "jiff02"] }
7376
```
7477

7578
## Examples
@@ -79,7 +82,7 @@ svix-ksuid = { version = "^0.6.0", features = ["serde"] }
7982
```rust
8083
use svix_ksuid::*;
8184

82-
let ksuid = Ksuid::new(None, None);
85+
let ksuid = Ksuid::now(None);
8386

8487
// Base62
8588
println!("{}", ksuid.to_string()); // also: ksuid.to_base62()
@@ -90,7 +93,7 @@ println!("{:?}", ksuid.bytes());
9093
// [13, 53, 196, 51, 225, 147, 62, 55, 242, 117, 112, 135, 99, 173, 199, 116, 90, 245, 231, 242]
9194

9295
// Timestamp (time::OffsetDateTime)
93-
println!("{:?}", ksuid.timestamp());
96+
println!("{:?}", ksuid.timestamp::<time::OffsetDateTime>());
9497
// 2021-05-21T20:04:03Z
9598

9699
// Timestamp (seconds)
@@ -106,9 +109,10 @@ println!("{:?}", ksuid.bytes());
106109

107110
```rust
108111
use svix_ksuid::*;
112+
use chrono::Utc;
109113

110114
// Timestamp is now, payload is randomly generated
111-
let ksuid = Ksuid::new(None, None);
115+
let ksuid = Ksuid::now(None);
112116

113117
// Explicitly set either
114118
let bytes = [12u8; Ksuid::PAYLOAD_BYTES];

deny.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[graph]
2+
targets = [
3+
{ triple = "x86_64-pc-windows-gnu" },
4+
{ triple = "x86_64-unknown-linux-musl" },
5+
{ triple = "x86_64-apple-darwin" },
6+
{ triple = "aarch64-apple-darwin" },
7+
]
8+
9+
[advisories]
10+
db-path = "~/.cargo/advisory-db"
11+
db-urls = ["https://github.com/rustsec/advisory-db"]
12+
yanked = "deny"
13+
ignore = [
14+
]
15+
16+
[licenses]
17+
allow = [
18+
"Apache-2.0",
19+
"Apache-2.0 WITH LLVM-exception",
20+
"BSD-2-Clause",
21+
"BSD-3-Clause",
22+
"CC0-1.0",
23+
"ISC",
24+
"MIT",
25+
"MPL-2.0",
26+
"Unicode-3.0",
27+
"Zlib",
28+
]
29+
unused-allowed-license = "allow"
30+
confidence-threshold = 0.8
31+
exceptions = [
32+
]
33+
34+
# TODO: Include internal crates
35+
[licenses.private]
36+
ignore = false
37+
registries = []
38+
39+
[bans]
40+
multiple-versions = "allow"
41+
wildcards = "allow"
42+
highlight = "all"
43+
allow = []
44+
deny = [
45+
# Versions containing the binary blob
46+
# See: https://github.com/serde-rs/serde/issues/2538
47+
{ name = "serde_derive", version = ">1.0.171, <1.0.184"},
48+
]
49+
skip = []
50+
skip-tree = []
51+
52+
[sources]
53+
unknown-registry = "deny"
54+
unknown-git = "deny"
55+
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
56+
allow-git = [
57+
]
58+
# there are several projects in here, so it's okay if we don't use them all

0 commit comments

Comments
 (0)