Skip to content

Commit

Permalink
fix wasm for cuid v1
Browse files Browse the repository at this point in the history
  • Loading branch information
mplanchard committed Jan 13, 2025
1 parent afbe9ce commit 591e311
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
command: "build"
args: "--target ${{ matrix.target }}"
- run: "cd crates/cuid2 && wasm-pack test --node"
- run: "cd crates/cuid1 && wasm-pack test --node"

lint:
name: "Lint"
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### Fixed

- (v1) Replaced `std::sys::SystemTime` with `web_time::SystemTime` so
that CUID generation does not panic in WASM builds

## [cuid2 v0.1.4]

### Fixed
Expand Down Expand Up @@ -206,7 +211,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Benchmark suite

[unreleased]: https://github.com/mplanchard/cuid-rust/compare/cuid2-v0.1.4...HEAD
[cuid2 v0.1.3]: https://github.com/mplanchard/cuid-rust/compare/cuid2-v0.1.3...cuid2-v0.1.4
[cuid2 v0.1.4]: https://github.com/mplanchard/cuid-rust/compare/cuid2-v0.1.3...cuid2-v0.1.4
[cuid2 v0.1.3]: https://github.com/mplanchard/cuid-rust/compare/cuid2-v0.1.2...cuid2-v0.1.3
[cuid 1.3.3]: https://github.com/mplanchard/cuid-rust/compare/cuid-v1.3.2...cuid-v1.3.3
[cuid2 v0.1.2]: https://github.com/mplanchard/cuid-rust/compare/cuid2-v0.1.1...cuid2-v0.1.2
Expand Down
7 changes: 0 additions & 7 deletions crates/cuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ repository.workspace = true
[dependencies]
cuid1.workspace = true
cuid2.workspace = true
num = { version = "0.4.0", features = ["num-bigint"] }
once_cell = "1.19.0"
rand.workspace = true

[dev-dependencies]
criterion.workspace = true


[lib]
name = "cuid"
Expand Down
33 changes: 22 additions & 11 deletions crates/cuid1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lib]
name = "cuid1"
path = "src/lib.rs"

[[bin]]
name = "cuid1"
path = "src/bin.rs"

[[bench]]
name = "cuid1"
harness = false

[dependencies]
cuid-util.workspace = true
num = { version = "0.4.0", features = ["num-bigint"] }
Expand All @@ -16,20 +28,19 @@ rand.workspace = true
uuid = { version = "1.10.0", features = ["v4"] }

[dev-dependencies]
criterion.workspace = true
paste.workspace = true
wasm-bindgen-test.workspace = true

# Not WASM deps
[target.'cfg(not(target_family = "wasm"))'.dependencies]
hostname = "0.4.0"

[lib]
name = "cuid1"
path = "src/lib.rs"

[[bin]]
name = "cuid1"
path = "src/bin.rs"
# WASM deps
[target.'cfg(target_family = "wasm")'.dependencies]
# Just specified so we can add a feature when the js feature is enabled.
# This works fine on wasm targets other than unknown-unknown
getrandom = { version = "0", features = ["js"] }
web-time = "1.1.0"

[[bench]]
name = "cuid1"
harness = false
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
criterion.workspace = true
10 changes: 9 additions & 1 deletion crates/cuid1/src/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ use crate::BASE;

static FINGERPRINT_PADDING: usize = 2;

/// Get a PID for the running process.
///
/// On WASM, which does not have PIDs, replace with a random number.
fn pid() -> String {
pad(FINGERPRINT_PADDING, to_base_string(process::id()))
#[cfg(not(target_family = "wasm"))]
let pid = process::id();
#[cfg(target_family = "wasm")]
let pid = rand::random::<u32>();

pad(FINGERPRINT_PADDING, to_base_string(pid))
}

/// Convert the hostname to a padded String in the appropriate base.
Expand Down
18 changes: 18 additions & 0 deletions crates/cuid1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,33 +158,51 @@ pub fn is_slug<S: AsRef<str>>(to_check: S) -> bool {
mod tests {
use super::*;

/// Run an already-defined test in WASM as well.
macro_rules! wasm_test {
($name:ident) => {
paste::paste! {
#[wasm_bindgen_test::wasm_bindgen_test]
fn [<wasm_ $name>]() {

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, nightly, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, beta, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::test --ignored)

function `wasm_slug_is_slug` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_correct_discrete_values` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_cuid` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_cuid_is_not_cuid_zero_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_len` is never used

Check warning on line 166 in crates/cuid1/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable, -p cuid1 -- collisions::single_thread --ignored --test-threads 1)

function `wasm_slug_is_slug` is never used
$name()
}
}
};
}

#[test]
fn correct_discrete_values() {
assert_eq!((crate::BASE as u32).pow(BLOCK_SIZE as u32), DISCRETE_VALUES);
}
wasm_test!(correct_discrete_values);

#[test]
fn cuid_len() {
assert_eq!(cuid().len(), 25);
}
wasm_test!(cuid_len);

#[test]
fn cuid_is_cuid() {
assert!(is_cuid(cuid()));
}
wasm_test!(cuid_is_cuid);

#[test]
fn cuid_is_not_cuid_zero_len() {
assert!(!is_cuid(""));
}
wasm_test!(cuid_is_not_cuid_zero_len);

#[test]
fn slug_len() {
assert!(slug().len() == 10);
}
wasm_test!(slug_len);

#[test]
fn slug_is_slug() {
assert!(is_slug(slug()));
}
wasm_test!(slug_is_slug);
}
4 changes: 4 additions & 0 deletions crates/cuid1/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// std::time::SystemTime panics on WASM, so use a different library there.
#[cfg(not(target_family = "wasm"))]
use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(target_family = "wasm")]
use web_time::{SystemTime, UNIX_EPOCH};

use crate::text::to_base_string;

Expand Down
2 changes: 0 additions & 2 deletions crates/cuid2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,6 @@ mod test {
#[ignore] // slow: run explicitly when desired
fn collisions() {
// generate ~10e6 IDs across all available cores

use wasm_bindgen_test::wasm_bindgen_test;
let cores = num_cpus::get();
let per_core = 10_000_000 / cores;

Expand Down

0 comments on commit 591e311

Please sign in to comment.