snippetrustMajor
How do you enable a Rust "crate feature"?
Viewed 0 times
youhowcratefeaturerustenable
Problem
I'm trying to use
This PRNG is feature-gated: to use, you must enable the crate feature
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:
But I get:
Feature
Are the docs wrong, or is there something I'm missing?
rand::SmallRng. The documentation saysThis 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 featureAre the docs wrong, or is there something I'm missing?
Solution
Specify the dependencies in Cargo.toml like so:
Alternatively:
Both work.
[dependencies]
rand = { version = "0.7.2", features = ["small_rng"] }
Alternatively:
[dependencies.rand]
version = "0.7.2"
features = ["small_rng"]
Both work.
Context
Stack Overflow Q#58480205, score: 84
Revisions (0)
No revisions yet.