45

I'm trying to use rand::SmallRng. The documentation says

This PRNG is feature-gated: to use, you must enable the crate feature small_rng.

I've been searching and can't figure out how to enable "crate features". The phrase isn't even used anywhere in the Rust docs. This is the best I could come up with:

[features]
default = ["small_rng"]

But I get:

Feature default includes small_rng which is neither a dependency nor another feature

Are the docs wrong, or is there something I'm missing?

kmdreko
  • 42,554
  • 6
  • 57
  • 106
brundolf
  • 1,170
  • 1
  • 9
  • 18

2 Answers2

60

Specify the dependencies in Cargo.toml like so:

[dependencies]
rand = { version = "0.7.2", features = ["small_rng"] }

Alternatively:

[dependencies.rand]
version = "0.7.2"
features = ["small_rng"]

Both work.

kmdreko
  • 42,554
  • 6
  • 57
  • 106
edwardw
  • 12,652
  • 3
  • 40
  • 51
1

To add a feature you can use. This works even if you have added the crate initially and want to add a feature later

cargo add rand -F small_rng
dhiraka
  • 817
  • 6
  • 13