diff --git a/Cargo.toml b/Cargo.toml index cc521ff..41cfa5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,13 +49,11 @@ serde = { version = "1.0", default-features = false, features = [ "alloc" ], opt zeroize = { version = "1.5", features = ["zeroize_derive"], optional = true } # Unexported dependnecies -bitcoin_hashes = { version = ">=0.12, <=0.13", default-features = false } +bitcoin_hashes = { version = ">=0.12, <=0.14", default-features = false, features = ["alloc"] } unicode-normalization = { version = "=0.1.22", default-features = false, optional = true } [dev-dependencies] -# Enabling the "rand" feature by default to run the benches -bip39 = { path = ".", features = ["rand"] } -bitcoin_hashes = ">=0.12,<0.14" # enable default features for test +bitcoin_hashes = ">=0.12,<=0.14" # enable default features for test [package.metadata.docs.rs] diff --git a/README.md b/README.md index aecd61f..ccc5c0f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ Use the `all-languages` feature to enable all languages. This crate supports Rust v1.41.1 and up and works with `no_std`. +The `bitcoin_hashes` range dependency effects the MSRV as follows + +- `bitcoin_hashes v0.12`: MSRV v1.41.1 +- `bitcoin_hashes v0.13`: MSRV v1.48.0 +- `bitcoin_hashes v0.14`: MSRV v1.56.1 + When using older version of Rust, you might have to pin the version of the `bitcoin_hashes` crate used as such: ``` diff --git a/benches/bench.rs b/benches/bench.rs index a11b129..a15926a 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -59,6 +59,7 @@ fn from_entropy(b: &mut Bencher) { }); } +#[cfg(feature = "rand")] #[bench] fn new_mnemonic(b: &mut Bencher) { b.iter(|| { diff --git a/src/internal_macros.rs b/src/internal_macros.rs index 4d4ece1..707effe 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -10,6 +10,7 @@ macro_rules! serde_string_impl { { use core::fmt::{self, Formatter}; use core::str::FromStr; + #[cfg(feature = "alloc")] use alloc::string::String; struct Visitor; @@ -34,6 +35,7 @@ macro_rules! serde_string_impl { self.visit_str(v) } + #[cfg(feature = "alloc")] fn visit_string(self, v: String) -> Result where E: $crate::serde::de::Error, diff --git a/src/lib.rs b/src/lib.rs index feb3ac2..7bed102 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,8 @@ pub extern crate serde; #[cfg(feature = "alloc")] use alloc::borrow::Cow; +#[cfg(all(feature = "alloc", not(feature = "std")))] +use alloc::{string::ToString, vec::Vec}; use core::{fmt, str}; /// We support a wide range of dependency versions for `rand` and `rand_core` and not @@ -620,6 +622,7 @@ impl Mnemonic { /// following assertion should hold: /// /// ```rust + /// # # [cfg(feature = "alloc")] { /// # use bip39::Mnemonic; /// # use bitcoin_hashes::{Hash, sha256, hex::FromHex}; /// # let ent = Vec::from_hex("98FE3D0FF6E955A484B0A1D0C9CE10F6").unwrap(); @@ -627,6 +630,7 @@ impl Mnemonic { /// let checksum_width = m.word_count() / 3; /// let shift_width = 8 - checksum_width; /// assert_eq!(sha256::Hash::hash(&m.to_entropy())[0] >> shift_width, m.checksum()); + /// # } /// ``` /// /// Note that since this library constrains initialization of `Mnemonic` instances through an