Skip to content

Commit d3aa089

Browse files
KazhuuMauri Mustonenjosephlr
authored
Add description about Cargo js feature for WebAssembly section (#280)
* add description about Cargo js feature * add note about different crate types * clean up * Fix wording/grammer * Remove "Indirect Depenencies" section * Note that libraries shouldn't add their own JS feature Signed-off-by: Joe Richey <[email protected]> Co-authored-by: Mauri Mustonen <[email protected]> Co-authored-by: Joe Richey <[email protected]>
1 parent 0b71d50 commit d3aa089

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/lib.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@
7474
//! and Node.js environments are supported, invoking the methods
7575
//! [described above](#supported-targets) using the [`wasm-bindgen`] toolchain.
7676
//!
77+
//! To enable the `js` Cargo feature, add the following to the `dependencies`
78+
//! section in your `Cargo.toml` file:
79+
//! ```toml
80+
//! [dependencies]
81+
//! getrandom = { version = "0.2", features = ["js"] }
82+
//! ```
83+
//!
84+
//! This can be done even if `getrandom` is not a direct dependency. Cargo
85+
//! allows crates to enable features for indirect dependencies.
86+
//!
87+
//! This feature should only be enabled for binary, test, or benchmark crates.
88+
//! Library crates should generally not enable this feature, leaving such a
89+
//! decision to *users* of their library. Also, libraries should not introduce
90+
//! their own `js` features *just* to enable `getrandom`'s `js` feature.
91+
//!
7792
//! This feature has no effect on targets other than `wasm32-unknown-unknown`.
7893
//!
7994
//! ### Custom implementations
@@ -88,16 +103,6 @@
88103
//! using `rdrand` and `js` Cargo features) continue using their normal
89104
//! implementations even if a function is registered.
90105
//!
91-
//! ### Indirect Dependencies
92-
//!
93-
//! If `getrandom` is not a direct dependency of your crate, you can still
94-
//! enable any of the above fallback behaviors by enabling the relevant
95-
//! feature in your root crate's `Cargo.toml`:
96-
//! ```toml
97-
//! [dependencies]
98-
//! getrandom = { version = "0.2", features = ["js"] }
99-
//! ```
100-
//!
101106
//! ## Early boot
102107
//!
103108
//! Sometimes, early in the boot process, the OS has not collected enough

0 commit comments

Comments
 (0)