hashes: Improve feature gating
Currently we have a few things mixed up in the feature gating of `hashes`. Observe that: - `io::Write` is not related to allocation. - "std" should be able to enable "alloc". Improve feature gating by doing: - Enable "alloc" from "std" and simplify `cfg` codebase wide. - Enable "internals/alloc" from "alloc". - Fix feature gating to use the minimal requirement i.e., "alloc".
This commit is contained in:
parent
f71da4e91a
commit
9ae3285882
|
@ -14,7 +14,7 @@ exclude = ["tests", "contrib"]
|
|||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["internals/std"]
|
||||
std = ["alloc", "internals/std"]
|
||||
alloc = ["internals/alloc"]
|
||||
schemars = ["actual-schemars", "dyn-clone"]
|
||||
serde-std = ["serde/std"]
|
||||
|
|
|
@ -49,12 +49,12 @@ fn from_engine(e: HashEngine) -> Hash {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test() {
|
||||
use crate::{hash160, Hash, HashEngine};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
struct Test {
|
||||
input: Vec<u8>,
|
||||
output: Vec<u8>,
|
||||
|
|
|
@ -15,12 +15,13 @@
|
|||
//! Hex encoding and decoding.
|
||||
//!
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
use crate::alloc::vec::Vec;
|
||||
|
||||
#[cfg(any(test, feature = "std"))]
|
||||
#[cfg(feature = "std")]
|
||||
use std::io;
|
||||
#[cfg(all(not(test), not(feature = "std"), feature = "core2"))]
|
||||
#[cfg(all(feature = "core2", not(feature = "std")))]
|
||||
use core2::io;
|
||||
|
||||
use core::{fmt, str};
|
||||
|
@ -201,7 +202,7 @@ impl_fromhex_array!(384);
|
|||
impl_fromhex_array!(512);
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use internals::hex::exts::DisplayHex;
|
||||
|
|
|
@ -245,7 +245,7 @@ impl<'de, T: Hash + Deserialize<'de>> Deserialize<'de> for Hmac<T> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test() {
|
||||
use crate::{sha256, HashEngine, HmacEngine, Hash, Hmac};
|
||||
|
||||
|
|
|
@ -102,8 +102,7 @@
|
|||
#[cfg(bench)] extern crate test;
|
||||
#[cfg(any(test, feature = "std"))] extern crate core;
|
||||
#[cfg(feature = "core2")] extern crate core2;
|
||||
#[cfg(feature = "alloc")] extern crate alloc;
|
||||
#[cfg(all(not(feature = "alloc"), feature = "std"))] use std as alloc;
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))] extern crate alloc;
|
||||
#[cfg(feature = "serde")] pub extern crate serde;
|
||||
#[cfg(all(test,feature = "serde"))] extern crate serde_test;
|
||||
|
||||
|
|
|
@ -405,7 +405,7 @@ impl HashEngine {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test() {
|
||||
use crate::{Hash, HashEngine, ripemd160};
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ impl HashEngine {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test() {
|
||||
use crate::{sha1, Hash, HashEngine};
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ mod tests {
|
|||
use crate::{Hash, HashEngine, sha256};
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test() {
|
||||
#[derive(Clone)]
|
||||
struct Test {
|
||||
|
|
|
@ -44,7 +44,7 @@ fn from_engine(e: sha256::HashEngine) -> Hash {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test() {
|
||||
use crate::{sha256, sha256d, Hash, HashEngine};
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ macro_rules! sha256t_hash_newtype {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{sha256, sha256t};
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::Hash;
|
||||
|
||||
const TEST_MIDSTATE: [u8; 32] = [
|
||||
|
@ -143,13 +143,13 @@ mod tests {
|
|||
}
|
||||
|
||||
/// A hash tagged with `$name`.
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
pub type TestHash = sha256t::Hash<TestHashTag>;
|
||||
|
||||
sha256t_hash_newtype!(NewTypeHash, NewTypeTag, TEST_MIDSTATE, 64, doc="test hash", true);
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test_sha256t() {
|
||||
assert_eq!(
|
||||
TestHash::hash(&[0]).to_string(),
|
||||
|
|
|
@ -308,7 +308,7 @@ impl HashEngine {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test() {
|
||||
use crate::{sha512, Hash, HashEngine};
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ fn from_engine(e: HashEngine) -> Hash {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(feature = "alloc")]
|
||||
fn test() {
|
||||
use crate::{sha512_256, Hash, HashEngine};
|
||||
|
||||
|
|
Loading…
Reference in New Issue