Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 5 additions & 4 deletions fixed-hash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
[package]
name = "fixed-hash"
version = "0.4.0"
version = "0.4.1"
Comment thread
ordian marked this conversation as resolved.
Outdated
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
homepage = "https://github.com/paritytech/parity-common"
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.5", optional = true, default-features = false }
rand = { version = "0.6", optional = true, default-features = false }
Comment thread
ordian marked this conversation as resolved.
Outdated
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
Copy Markdown
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
Copy Markdown
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


[target.'cfg(not(target_os = "unknown"))'.dependencies]
libc = { version = "0.2", optional = true, default-features = false }
Expand Down
21 changes: 10 additions & 11 deletions fixed-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@
#![cfg_attr(not(feature = "std"), no_std)]

// Re-export liballoc using an alias so that the macros can work without
// requiring `extern crate alloc` downstream.
// requiring `use alloc` downstream.
#[cfg(not(feature = "std"))]
#[doc(hidden)]
pub extern crate alloc as alloc_;
pub use alloc as alloc_;
Comment thread
expenses marked this conversation as resolved.
Outdated

// 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;

#[macro_use]
mod hash;
Expand Down
22 changes: 11 additions & 11 deletions fixed-hash/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,29 @@ mod from_low_u64 {
#[cfg(feature = "rand")]
mod rand {
use super::*;
use rand::{SeedableRng, 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([0x82, 0xa0, 0x7f, 0x0e])
);
}

#[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([0x82, 0xa0, 0x7f, 0x0e])
)
}
}
Expand All @@ -283,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 @@ -293,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