diff --git a/src/lib.rs b/src/lib.rs index 56c932a..1cc0428 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ extern crate alloc; extern crate bitcoin_hashes; -#[cfg(feature = "alloc")] +#[cfg(any(feature = "alloc", feature = "std"))] extern crate unicode_normalization; #[cfg(feature = "rand")] @@ -45,14 +45,13 @@ pub extern crate serde; use core::{fmt, str}; -#[cfg(feature = "alloc")] use alloc::borrow::Cow; #[cfg(feature = "std")] use std::error; use bitcoin_hashes::{sha256, Hash}; -#[cfg(feature = "alloc")] +#[cfg(any(feature = "alloc", feature = "std"))] use unicode_normalization::UnicodeNormalization; #[cfg(feature = "zeroize")] @@ -95,7 +94,7 @@ impl AmbiguousLanguages { } /// Returns a vector of the possible languages. - #[cfg(feature = "alloc")] + #[cfg(any(feature = "alloc", feature = "std"))] pub fn to_vec(&self) -> Vec { self.iter().collect() } @@ -183,7 +182,7 @@ impl Mnemonic { /// Performing this on a [Cow] means that all allocations for normalization /// can be avoided for languages without special UTF8 characters. #[inline] - #[cfg(feature = "alloc")] + #[cfg(any(feature = "alloc", feature = "std"))] pub fn normalize_utf8_cow<'a>(cow: &mut Cow<'a, str>) { let is_nfkd = unicode_normalization::is_nfkd_quick(cow.as_ref().chars()); if is_nfkd != unicode_normalization::IsNormalized::Yes { @@ -506,7 +505,7 @@ impl Mnemonic { } /// Parse a mnemonic in the given language. - #[cfg(feature = "alloc")] + #[cfg(any(feature = "alloc", feature = "std"))] pub fn parse_in<'a, S: Into>>( language: Language, s: S, @@ -517,7 +516,7 @@ impl Mnemonic { } /// Parse a mnemonic and detect the language from the enabled languages. - #[cfg(feature = "alloc")] + #[cfg(any(feature = "alloc", feature = "std"))] pub fn parse<'a, S: Into>>(s: S) -> Result { let mut cow = s.into(); Mnemonic::normalize_utf8_cow(&mut cow); @@ -547,7 +546,7 @@ impl Mnemonic { } /// Convert to seed bytes. - #[cfg(feature = "alloc")] + #[cfg(any(feature = "alloc", feature = "std"))] pub fn to_seed<'a, P: Into>>(&self, passphrase: P) -> [u8; 64] { let normalized_passphrase = { let mut cow = passphrase.into(); @@ -596,7 +595,7 @@ impl Mnemonic { } /// Convert the mnemonic back to the entropy used to generate it. - #[cfg(feature = "alloc")] + #[cfg(any(feature = "alloc", feature = "std"))] pub fn to_entropy(&self) -> Vec { let (arr, len) = self.to_entropy_array(); arr[0..len].to_vec() @@ -619,11 +618,11 @@ impl str::FromStr for Mnemonic { type Err = Error; fn from_str(s: &str) -> Result { - #[cfg(feature = "alloc")] + #[cfg(any(feature = "alloc", feature = "std"))] { Mnemonic::parse(s) } - #[cfg(not(feature = "std"))] + #[cfg(all(not(feature = "alloc"), not(feature = "std")))] { Mnemonic::parse_normalized(s) }