Skip to content

Commit fe54a47

Browse files
expensesdvdplm
authored andcommitted
[fixed-hash] Migrated code to the 2018 edition and updated dependencies (#223)
* Migrated code and updated dependencies * . * Revert "." This reverts commit 57ae6b5. * Downgrade rand to 0.6 due to breaking changes with 0.7 * Update fixed-hash/Cargo.toml Co-Authored-By: Andronik Ordian <write@reusable.software> * Fixed some things * fix comment
1 parent c2f593c commit fe54a47

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

fixed-hash/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ repository = "https://github.com/paritytech/parity-common"
88
description = "Macros to define custom fixed-size hash types"
99
documentation = "https://docs.rs/fixed-hash/"
1010
readme = "README.md"
11+
edition = "2018"
1112

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

1516
[dependencies]
1617
rand = { version = "0.7", optional = true, default-features = false }
1718
rustc-hex = { version = "2.0", optional = true, default-features = false }
18-
quickcheck = { version = "0.7", optional = true }
19+
quickcheck = { version = "0.9", optional = true }
1920
byteorder = { version = "1.2", optional = true, default-features = false }
20-
static_assertions = "0.2"
21+
static_assertions = "0.3"
2122

2223
[dev-dependencies]
2324
rand_xorshift = "0.2.0"

fixed-hash/src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@
1515
pub extern crate alloc as alloc_;
1616

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

2222
#[cfg(all(feature = "libc", not(target_os = "unknown")))]
2323
#[doc(hidden)]
24-
pub extern crate libc;
24+
pub use libc;
2525

2626
// This disables a warning for unused #[macro_use(..)]
2727
// which is incorrect since the compiler does not check
2828
// for all available configurations.
2929
#[allow(unused_imports)]
30-
#[macro_use(const_assert)]
3130
#[doc(hidden)]
32-
pub extern crate static_assertions;
31+
pub use static_assertions;
3332

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

3938
#[cfg(feature = "byteorder")]
4039
#[doc(hidden)]
41-
pub extern crate byteorder;
40+
pub use byteorder;
4241

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

4746
#[cfg(feature = "rustc-hex")]
4847
#[doc(hidden)]
49-
pub extern crate rustc_hex;
48+
pub use rustc_hex;
5049

5150
#[cfg(feature = "rand")]
5251
#[doc(hidden)]
53-
pub extern crate rand;
52+
pub use rand;
5453

5554
#[cfg(feature = "quickcheck")]
5655
#[doc(hidden)]
57-
pub extern crate quickcheck;
56+
pub use quickcheck;
5857

5958
#[cfg(test)]
6059
extern crate rand_xorshift;

fixed-hash/src/tests.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,30 +250,29 @@ mod from_low_u64 {
250250
#[cfg(feature = "rand")]
251251
mod rand {
252252
use super::*;
253-
use rand::SeedableRng;
254-
use rand_xorshift::XorShiftRng;
253+
use ::rand::{SeedableRng, rngs::StdRng};
255254

256255
#[test]
257256
fn random() {
258-
let default_seed = <XorShiftRng as SeedableRng>::Seed::default();
259-
let mut rng = XorShiftRng::from_seed(default_seed);
257+
let default_seed = <StdRng as SeedableRng>::Seed::default();
258+
let mut rng = StdRng::from_seed(default_seed);
260259
assert_eq!(
261260
H32::random_using(&mut rng),
262-
H32::from([0x43, 0xCA, 0x64, 0xED])
261+
H32::from([0x76, 0xa0, 0x40, 0x53])
263262
);
264263
}
265264

266265
#[test]
267266
fn randomize() {
268-
let default_seed = <XorShiftRng as SeedableRng>::Seed::default();
269-
let mut rng = XorShiftRng::from_seed(default_seed);
267+
let default_seed = <StdRng as SeedableRng>::Seed::default();
268+
let mut rng = StdRng::from_seed(default_seed);
270269
assert_eq!(
271270
{
272271
let mut ret = H32::zero();
273272
ret.randomize_using(&mut rng);
274273
ret
275274
},
276-
H32::from([0x43, 0xCA, 0x64, 0xED])
275+
H32::from([0x76, 0xa0, 0x40, 0x53])
277276
)
278277
}
279278
}
@@ -284,7 +283,7 @@ mod from_str {
284283

285284
#[test]
286285
fn valid() {
287-
use core_::str::FromStr;
286+
use crate::core_::str::FromStr;
288287

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

295294
#[test]
296295
fn empty_str() {
297-
use core_::str::FromStr;
296+
use crate::core_::str::FromStr;
298297
assert!(H64::from_str("").is_err())
299298
}
300299

301300
#[test]
302301
fn invalid_digits() {
303-
use core_::str::FromStr;
302+
use crate::core_::str::FromStr;
304303
assert!(H64::from_str("Hello, World!").is_err())
305304
}
306305

307306
#[test]
308307
fn too_many_digits() {
309-
use core_::str::FromStr;
308+
use crate::core_::str::FromStr;
310309
assert!(H64::from_str("0123456789ABCDEF0").is_err())
311310
}
312311
}

0 commit comments

Comments
 (0)