Make rand_core optional and expose rand and rand_core crates

This commit is contained in:
Steven Roose 2023-02-26 06:26:23 +00:00
parent f348415f11
commit 8e6ba6de9b
No known key found for this signature in database
GPG Key ID: 2F2A88D7F8D68E87
2 changed files with 10 additions and 7 deletions

View File

@ -14,6 +14,7 @@ edition = "2018"
[features]
default = [ "std" ]
std = [ "unicode-normalization", "serde/std" ]
rand = [ "crate_rand", "rand_core" ]
# Note: English is the standard for bip39 so always included
chinese-simplified = []
@ -37,8 +38,8 @@ all-languages = [
]
[dependencies]
rand_core = ">=0.4.0, <0.7.0"
rand = { version = ">=0.6.0, <0.9.0", optional = true }
rand_core = { version = ">=0.4.0, <0.7.0", optional = true }
crate_rand = { package = "rand", version = ">=0.6.0, <0.9.0", optional = true }
serde = { version = "1.0", default-features = false, features = [ "alloc" ], optional = true }
# Enabling this feature raises the MSRV to 1.51
@ -49,6 +50,7 @@ bitcoin_hashes = { version = "0.11.0", default-features = false }
unicode-normalization = { version = "=0.1.9", optional = true }
[dev-dependencies]
rand = { version = "0.8.5", optional = false }
rand_core = { version = "0.6.4", optional = false }
crate_rand = { package = "rand", version = "0.8.5", optional = false }
bitcoin_hashes = "0.11.0" # enable default features for test

View File

@ -31,13 +31,14 @@ pub extern crate core;
extern crate alloc;
extern crate bitcoin_hashes;
extern crate rand_core;
#[cfg(feature = "std")]
extern crate unicode_normalization;
#[cfg(feature = "rand_core")]
pub extern crate rand_core;
#[cfg(feature = "rand")]
extern crate rand;
pub extern crate crate_rand as rand;
#[cfg(feature = "serde")]
pub extern crate serde;
@ -248,14 +249,14 @@ impl Mnemonic {
/// Example:
///
/// ```
/// extern crate rand;
/// extern crate bip39;
///
/// use bip39::{Mnemonic, Language};
///
/// let mut rng = rand::thread_rng();
/// let mut rng = bip39::rand::thread_rng();
/// let m = Mnemonic::generate_in_with(&mut rng, Language::English, 24).unwrap();
/// ```
#[cfg(feature = "rand_core")]
pub fn generate_in_with<R>(
rng: &mut R,
language: Language,