Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions fixed-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ repository = "https://github.com/paritytech/parity-common"
description = "Macros to define custom fixed-size hash types"
documentation = "https://docs.rs/fixed-hash/"
readme = "README.md"
edition = "2018"

[package.metadata.docs.rs]
features = ["quickcheck", "api-dummy"]

[dependencies]
rand = { version = "0.7", optional = true, default-features = false }
rustc-hex = { version = "2.0", optional = true, default-features = false }
quickcheck = { version = "0.7", optional = true }
quickcheck = { version = "0.9", optional = true }
byteorder = { version = "1.2", optional = true, default-features = false }
static_assertions = "0.2"
static_assertions = "0.3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a technically a breaking change, since we pub use these crates. But I doubt someone will get an error because of that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yupp, the same applies to quickcheck


[dev-dependencies]
rand_xorshift = "0.2.0"
Expand Down
17 changes: 8 additions & 9 deletions fixed-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@
pub extern crate alloc as alloc_;

// Re-export libcore using an alias so that the macros can work without
// requiring `extern crate core` downstream.
// requiring `use core` downstream.
#[doc(hidden)]
pub extern crate core as core_;
pub use core as core_;

#[cfg(all(feature = "libc", not(target_os = "unknown")))]
#[doc(hidden)]
pub extern crate libc;
pub use libc;

// This disables a warning for unused #[macro_use(..)]
// which is incorrect since the compiler does not check
// for all available configurations.
#[allow(unused_imports)]
#[macro_use(const_assert)]
#[doc(hidden)]
pub extern crate static_assertions;
pub use static_assertions;

// Export `const_assert` macro so that users of this crate do not
// have to import the `static_assertions` crate themselves.
Expand All @@ -38,23 +37,23 @@ pub use static_assertions::const_assert;

#[cfg(feature = "byteorder")]
#[doc(hidden)]
pub extern crate byteorder;
pub use byteorder;

#[cfg(not(feature = "libc"))]
#[doc(hidden)]
pub mod libc {}

#[cfg(feature = "rustc-hex")]
#[doc(hidden)]
pub extern crate rustc_hex;
pub use rustc_hex;

#[cfg(feature = "rand")]
#[doc(hidden)]
pub extern crate rand;
pub use rand;

#[cfg(feature = "quickcheck")]
#[doc(hidden)]
pub extern crate quickcheck;
pub use quickcheck;

#[cfg(test)]
extern crate rand_xorshift;
Expand Down
23 changes: 11 additions & 12 deletions fixed-hash/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,30 +250,29 @@ mod from_low_u64 {
#[cfg(feature = "rand")]
mod rand {
use super::*;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use ::rand::{SeedableRng, rngs::StdRng};

#[test]
fn random() {
let default_seed = <XorShiftRng as SeedableRng>::Seed::default();
let mut rng = XorShiftRng::from_seed(default_seed);
let default_seed = <StdRng as SeedableRng>::Seed::default();
let mut rng = StdRng::from_seed(default_seed);
assert_eq!(
H32::random_using(&mut rng),
H32::from([0x43, 0xCA, 0x64, 0xED])
H32::from([0x76, 0xa0, 0x40, 0x53])
);
}

#[test]
fn randomize() {
let default_seed = <XorShiftRng as SeedableRng>::Seed::default();
let mut rng = XorShiftRng::from_seed(default_seed);
let default_seed = <StdRng as SeedableRng>::Seed::default();
let mut rng = StdRng::from_seed(default_seed);
assert_eq!(
{
let mut ret = H32::zero();
ret.randomize_using(&mut rng);
ret
},
H32::from([0x43, 0xCA, 0x64, 0xED])
H32::from([0x76, 0xa0, 0x40, 0x53])
)
}
}
Expand All @@ -284,7 +283,7 @@ mod from_str {

#[test]
fn valid() {
use core_::str::FromStr;
use crate::core_::str::FromStr;

assert_eq!(
H64::from_str("0123456789ABCDEF").unwrap(),
Expand All @@ -294,19 +293,19 @@ mod from_str {

#[test]
fn empty_str() {
use core_::str::FromStr;
use crate::core_::str::FromStr;
assert!(H64::from_str("").is_err())
}

#[test]
fn invalid_digits() {
use core_::str::FromStr;
use crate::core_::str::FromStr;
assert!(H64::from_str("Hello, World!").is_err())
}

#[test]
fn too_many_digits() {
use core_::str::FromStr;
use crate::core_::str::FromStr;
assert!(H64::from_str("0123456789ABCDEF0").is_err())
}
}
Expand Down