From 252dce1bad393bd5249354feff3b17a1ac0e155b Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Thu, 19 Sep 2019 14:13:38 -0700 Subject: [PATCH] Use rand::thread_rng to impl Default for Nonce. --- zebra-network/Cargo.toml | 1 + zebra-network/src/types.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/zebra-network/Cargo.toml b/zebra-network/Cargo.toml index 24fced644..d5d68a8aa 100644 --- a/zebra-network/Cargo.toml +++ b/zebra-network/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +rand = "0.7" byteorder = "1.3" chrono = "0.4" failure = "0.1" diff --git a/zebra-network/src/types.rs b/zebra-network/src/types.rs index d4d98ae72..881a6e7ec 100644 --- a/zebra-network/src/types.rs +++ b/zebra-network/src/types.rs @@ -17,3 +17,10 @@ pub struct Services(pub u64); /// A nonce used in the networking layer to identify messages. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Nonce(pub u64); + +impl Default for Nonce { + fn default() -> Self { + use rand::{thread_rng, Rng}; + Self(thread_rng().gen()) + } +}