Skip to content

Make rand / rand_distr optional behind a default-on rand feature#104

Merged
Axect merged 1 commit into
devfrom
features/optional-rand
Jul 6, 2026
Merged

Make rand / rand_distr optional behind a default-on rand feature#104
Axect merged 1 commit into
devfrom
features/optional-rand

Conversation

@Axect

@Axect Axect commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Implements #88 (issue kept open intentionally).

Sandboxed targets (Typst plugins, wasm32) cannot use stateful RNG, so this makes the random sampling stack optional:

  • rand / rand_distr become optional dependencies behind a new default-on rand feature. Existing users see no change; default-features = false drops the RNG stack entirely and leaves the deterministic core (ODE solvers, numerical integration, splines, linear algebra).
  • Gated behind the feature: statistics::dist, statistics::rand, util::wrapper, the rand() / rand_with_rng() / rand_with_dist() constructors, the runif! / rnorm! / dnorm! / pnorm! / rt! / dt! / pt! / rand! macros, the dist Printable impls, and the fuga / prelude re-exports of all of the above.
  • complex/matrix.rs imported num_traits through rand_distr's re-export; it now uses num-traits directly (optional dep tied to the complex feature).
  • Examples that sample declare required-features = ["rand"]; rand-dependent tests and doctests are cfg-gated.
  • New CI job no-rand-wasm: cargo test --no-default-features plus a wasm32-unknown-unknown build, so the no-rand configuration cannot silently regress.

Verified locally: default 472 tests, complex 512 tests, no-default 444 tests, wasm32 build, clippy zero errors in both configurations.

…88)

Sandboxed targets (Typst plugins, wasm32) cannot use stateful RNG, so
the random sampling stack is now optional:

* rand / rand_distr become optional dependencies behind a new
  default-on `rand` feature; existing users see no change, and
  `default-features = false` drops the RNG stack entirely.
* Gated behind the feature: statistics::dist, statistics::rand,
  util::wrapper, the rand() / rand_with_rng() / rand_with_dist()
  constructors, the runif! / rnorm! / dnorm! / pnorm! / rt! / dt! /
  pt! / rand! macros, the dist Printable impls, and the fuga /
  prelude re-exports of all of the above.
* complex/matrix.rs imported num_traits through rand_distr's
  re-export; it now uses num-traits directly (new optional dep tied
  to the complex feature).
* Examples that sample (dist, matmul, optim, clippy_verify) declare
  required-features = ["rand"]; rand-dependent tests and doctests
  are cfg-gated.
* New CI job: cargo test --no-default-features plus a
  wasm32-unknown-unknown build, so the deterministic core (ODE,
  integration, splines, linear algebra) cannot silently regress.

Verified locally: default 472 tests, complex 512 tests, no-default
444 tests, wasm32 build, clippy zero errors in both configurations.
@Axect Axect merged commit 35c3dfd into dev Jul 6, 2026
16 checks passed
@Axect Axect deleted the features/optional-rand branch July 6, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant