Use Rust 2018 idioms consistently.

Apply `cargo fix --edition-idioms`.
This commit is contained in:
Andreas Fackler 2019-01-09 11:56:40 +01:00
parent 87b1d45d97
commit bd74cc2fa9
17 changed files with 40 additions and 40 deletions

View File

@ -14,7 +14,7 @@ use hbbft::SourcedMessage;
/// A communication task connects a remote node to the thread that manages the /// A communication task connects a remote node to the thread that manages the
/// consensus algorithm. /// consensus algorithm.
pub struct CommsTask<'a, M: 'a> { pub struct CommsTask<'a, M> {
/// The transmit side of the multiple producer channel from comms threads. /// The transmit side of the multiple producer channel from comms threads.
tx: &'a Sender<SourcedMessage<M, usize>>, tx: &'a Sender<SourcedMessage<M, usize>>,
/// The receive side of the channel to the comms thread. /// The receive side of the channel to the comms thread.

View File

@ -522,7 +522,7 @@ impl<N: NodeIdT, S: SessionIdT> BinaryAgreement<N, S> {
} }
impl<N: NodeIdT, S: SessionIdT> fmt::Display for BinaryAgreement<N, S> { impl<N: NodeIdT, S: SessionIdT> fmt::Display for BinaryAgreement<N, S> {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
write!( write!(
f, f,
"{:?} BA {} epoch {} ({})", "{:?} BA {} epoch {} ({})",

View File

@ -34,7 +34,7 @@ impl<'a, N: Ord> IntoIterator for &'a BoolMultimap<N> {
} }
} }
pub struct Iter<'a, N: 'a> { pub struct Iter<'a, N> {
key: bool, key: bool,
set_iter: btree_set::Iter<'a, N>, set_iter: btree_set::Iter<'a, N>,
map: &'a BoolMultimap<N>, map: &'a BoolMultimap<N>,

View File

@ -410,7 +410,7 @@ impl<N: NodeIdT> Broadcast<N> {
} }
impl<N: NodeIdT> fmt::Display for Broadcast<N> { impl<N: NodeIdT> fmt::Display for Broadcast<N> {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
write!(f, "{:?} Broadcast({:?})", self.our_id(), self.proposer_id) write!(f, "{:?} Broadcast({:?})", self.our_id(), self.proposer_id)
} }
} }

View File

@ -43,7 +43,7 @@ impl Distribution<Message> for Standard {
} }
impl Debug for Message { impl Debug for Message {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {
Message::Value(ref v) => f.debug_tuple("Value").field(&HexProof(v)).finish(), Message::Value(ref v) => f.debug_tuple("Value").field(&HexProof(v)).finish(),
Message::Echo(ref v) => f.debug_tuple("Echo").field(&HexProof(v)).finish(), Message::Echo(ref v) => f.debug_tuple("Echo").field(&HexProof(v)).finish(),
@ -52,10 +52,10 @@ impl Debug for Message {
} }
} }
/// Wrapper for a `Proof`, to print the bytes as a shortened hexadecimal number. /// Wrapper for a `Proof`, to print the bytes as a shortened hexadecimal number.
pub struct HexProof<'a, T: 'a>(pub &'a Proof<T>); pub struct HexProof<'a, T>(pub &'a Proof<T>);
impl<'a, T: AsRef<[u8]>> fmt::Debug for HexProof<'a, T> { impl<'a, T: AsRef<[u8]>> fmt::Debug for HexProof<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
"Proof {{ #{}, root_hash: {:0.10}, value: {:0.10}, .. }}", "Proof {{ #{}, root_hash: {:0.10}, value: {:0.10}, .. }}",

View File

@ -536,7 +536,7 @@ where
C: Contribution + Serialize + DeserializeOwned, C: Contribution + Serialize + DeserializeOwned,
N: NodeIdT + Serialize + DeserializeOwned, N: NodeIdT + Serialize + DeserializeOwned,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
write!(f, "{:?} DHB(era: {})", self.our_id(), self.era) write!(f, "{:?} DHB(era: {})", self.our_id(), self.era)
} }
} }

View File

@ -404,7 +404,7 @@ struct EpochId {
} }
impl Display for EpochId { impl Display for EpochId {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
write!(f, "{}/{}", self.hb_id, self.epoch) write!(f, "{}/{}", self.hb_id, self.epoch)
} }
} }

View File

@ -119,7 +119,7 @@
#![allow(clippy::module_inception, clippy::new_ret_no_self)] #![allow(clippy::module_inception, clippy::new_ret_no_self)]
#![warn(missing_docs)] #![warn(missing_docs)]
pub extern crate threshold_crypto as crypto; pub use threshold_crypto as crypto;
mod fault_log; mod fault_log;
mod messaging; mod messaging;

View File

@ -170,7 +170,7 @@ impl<N: NodeIdT, S: SessionIdT> Subset<N, S> {
} }
impl<N: NodeIdT, S: SessionIdT> fmt::Display for Subset<N, S> { impl<N: NodeIdT, S: SessionIdT> fmt::Display for Subset<N, S> {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
write!(f, "{:?} Subset({})", self.our_id(), self.session_id) write!(f, "{:?} Subset({})", self.our_id(), self.session_id)
} }
} }
@ -185,7 +185,7 @@ pub struct BaSessionId<S> {
} }
impl<S: fmt::Display> fmt::Display for BaSessionId<S> { impl<S: fmt::Display> fmt::Display for BaSessionId<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
write!( write!(
f, f,
"subset {}, proposer #{}", "subset {}, proposer #{}",

View File

@ -225,7 +225,7 @@ impl From<bincode::Error> for Error {
pub struct Part(BivarCommitment, Vec<Ciphertext>); pub struct Part(BivarCommitment, Vec<Ciphertext>);
impl Debug for Part { impl Debug for Part {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_tuple("Part") f.debug_tuple("Part")
.field(&format!("<degree {}>", self.0.degree())) .field(&format!("<degree {}>", self.0.degree()))
.field(&format!("<{} rows>", self.1.len())) .field(&format!("<{} rows>", self.1.len()))
@ -242,7 +242,7 @@ impl Debug for Part {
pub struct Ack(u64, Vec<Ciphertext>); pub struct Ack(u64, Vec<Ciphertext>);
impl Debug for Ack { impl Debug for Ack {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_tuple("Ack") f.debug_tuple("Ack")
.field(&self.0) .field(&self.0)
.field(&format!("<{} values>", self.1.len())) .field(&format!("<{} values>", self.1.len()))

View File

@ -271,7 +271,7 @@ impl<N: NodeIdT> ThresholdSign<N> {
} }
impl<N: NodeIdT> fmt::Display for ThresholdSign<N> { impl<N: NodeIdT> fmt::Display for ThresholdSign<N> {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
write!(f, "{:?} TS({:?})", self.our_id(), self.doc_hash) write!(f, "{:?} TS({:?})", self.our_id(), self.doc_hash)
} }
} }

View File

@ -8,7 +8,7 @@ use std::fmt;
use hex_fmt::HexFmt; use hex_fmt::HexFmt;
/// Prints a byte slice as shortened hexadecimal in debug output. /// Prints a byte slice as shortened hexadecimal in debug output.
pub fn fmt_hex<T: AsRef<[u8]>>(bytes: T, f: &mut fmt::Formatter) -> fmt::Result { pub fn fmt_hex<T: AsRef<[u8]>>(bytes: T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:10}", HexFmt(bytes)) write!(f, "{:10}", HexFmt(bytes))
} }

View File

@ -295,7 +295,7 @@ impl AbaCommonCoinAdversary {
} }
} }
fn inject_stage_messages(&mut self, net: &mut NetMutHandle<Algo, Self>) { fn inject_stage_messages(&mut self, net: &mut NetMutHandle<'_, Algo, Self>) {
if self.sent_stage_messages { if self.sent_stage_messages {
return; return;
} }
@ -378,7 +378,7 @@ impl AbaCommonCoinAdversary {
} }
impl Adversary<Algo> for AbaCommonCoinAdversary { impl Adversary<Algo> for AbaCommonCoinAdversary {
fn pre_crank<R: Rng>(&mut self, mut net: NetMutHandle<Algo, Self>, rng: &mut R) { fn pre_crank<R: Rng>(&mut self, mut net: NetMutHandle<'_, Algo, Self>, rng: &mut R) {
self.inject_stage_messages(&mut net); self.inject_stage_messages(&mut net);
net.sort_messages_by(|a, b| { net.sort_messages_by(|a, b| {
a.payload() a.payload()
@ -414,7 +414,7 @@ impl Adversary<Algo> for AbaCommonCoinAdversary {
fn tamper<R: Rng>( fn tamper<R: Rng>(
&mut self, &mut self,
_: NetMutHandle<Algo, Self>, _: NetMutHandle<'_, Algo, Self>,
msg: NetMessage<Algo>, msg: NetMessage<Algo>,
_rng: &mut R, _rng: &mut R,
) -> Result<CpStep<Algo>, CrankError<Algo>> { ) -> Result<CpStep<Algo>, CrankError<Algo>> {

View File

@ -46,7 +46,7 @@ use crate::net::{CrankError, NetMessage, Node, VirtualNet};
/// ///
/// Allows querying public information of the network or getting immutable handles to any node. /// Allows querying public information of the network or getting immutable handles to any node.
#[derive(Debug)] #[derive(Debug)]
pub struct NetHandle<'a, D: 'a, A>(&'a VirtualNet<D, A>) pub struct NetHandle<'a, D, A>(&'a VirtualNet<D, A>)
where where
D: ConsensusProtocol, D: ConsensusProtocol,
D::Message: Clone, D::Message: Clone,
@ -62,7 +62,7 @@ where
{ {
/// Returns a node handle iterator over all nodes in the network. /// Returns a node handle iterator over all nodes in the network.
#[inline] #[inline]
pub fn nodes(&self) -> impl Iterator<Item = NodeHandle<D>> { pub fn nodes(&self) -> impl Iterator<Item = NodeHandle<'_, D>> {
self.0.nodes().map(NodeHandle::new) self.0.nodes().map(NodeHandle::new)
} }
@ -79,7 +79,7 @@ where
/// Returns a node handle iterator over all correct nodes in the network. /// Returns a node handle iterator over all correct nodes in the network.
#[inline] #[inline]
pub fn correct_nodes(&self) -> impl Iterator<Item = NodeHandle<D>> { pub fn correct_nodes(&self) -> impl Iterator<Item = NodeHandle<'_, D>> {
self.0.correct_nodes().map(NodeHandle::new) self.0.correct_nodes().map(NodeHandle::new)
} }
@ -91,7 +91,7 @@ where
/// Returns a handle to a specific node handle. /// Returns a handle to a specific node handle.
#[inline] #[inline]
pub fn get(&self, id: D::NodeId) -> Option<NodeHandle<D>> { pub fn get(&self, id: D::NodeId) -> Option<NodeHandle<'_, D>> {
self.0.get(id).map(NodeHandle::new) self.0.get(id).map(NodeHandle::new)
} }
} }
@ -112,7 +112,7 @@ pub enum QueuePosition {
/// Allows reordering of messages, injecting new ones into the network queue and getting mutable /// Allows reordering of messages, injecting new ones into the network queue and getting mutable
/// handles to nodes. /// handles to nodes.
#[derive(Debug)] #[derive(Debug)]
pub struct NetMutHandle<'a, D: 'a, A>(&'a mut VirtualNet<D, A>) pub struct NetMutHandle<'a, D, A>(&'a mut VirtualNet<D, A>)
where where
D: ConsensusProtocol, D: ConsensusProtocol,
D::Message: Clone, D::Message: Clone,
@ -133,7 +133,7 @@ where
/// Returns a mutable node handle iterator over all nodes in the network. /// Returns a mutable node handle iterator over all nodes in the network.
#[inline] #[inline]
pub fn nodes_mut(&mut self) -> impl Iterator<Item = NodeMutHandle<D>> { pub fn nodes_mut(&mut self) -> impl Iterator<Item = NodeMutHandle<'_, D>> {
self.0.nodes_mut().map(NodeMutHandle::new) self.0.nodes_mut().map(NodeMutHandle::new)
} }
@ -148,7 +148,7 @@ where
/// Returns a mutable node handle iterator over all nodes in the network. /// Returns a mutable node handle iterator over all nodes in the network.
#[inline] #[inline]
pub fn correct_nodes_mut(&mut self) -> impl Iterator<Item = NodeMutHandle<D>> { pub fn correct_nodes_mut(&mut self) -> impl Iterator<Item = NodeMutHandle<'_, D>> {
self.0.correct_nodes_mut().map(NodeMutHandle::new) self.0.correct_nodes_mut().map(NodeMutHandle::new)
} }
@ -233,14 +233,14 @@ where
D::Output: Clone, D::Output: Clone,
{ {
#[inline] #[inline]
fn from(n: NetMutHandle<D, A>) -> NetHandle<D, A> { fn from(n: NetMutHandle<'_, D, A>) -> NetHandle<'_, D, A> {
NetHandle(n.0) NetHandle(n.0)
} }
} }
/// Immutable node handle. /// Immutable node handle.
#[derive(Debug)] #[derive(Debug)]
pub struct NodeHandle<'a, D: 'a>(&'a Node<D>) pub struct NodeHandle<'a, D>(&'a Node<D>)
where where
D: ConsensusProtocol; D: ConsensusProtocol;
@ -284,7 +284,7 @@ where
/// Mutable node handle. /// Mutable node handle.
#[derive(Debug)] #[derive(Debug)]
pub struct NodeMutHandle<'a, D: 'a>(&'a mut Node<D>) pub struct NodeMutHandle<'a, D>(&'a mut Node<D>)
where where
D: ConsensusProtocol; D: ConsensusProtocol;
@ -334,7 +334,7 @@ where
/// ///
/// The default implementation does not alter the passed network in any way. /// The default implementation does not alter the passed network in any way.
#[inline] #[inline]
fn pre_crank<R: Rng>(&mut self, _net: NetMutHandle<D, Self>, _rng: &mut R) {} fn pre_crank<R: Rng>(&mut self, _net: NetMutHandle<'_, D, Self>, _rng: &mut R) {}
/// Tamper with a faulty node's operation. /// Tamper with a faulty node's operation.
/// ///
@ -352,7 +352,7 @@ where
#[inline] #[inline]
fn tamper<R: Rng>( fn tamper<R: Rng>(
&mut self, &mut self,
mut net: NetMutHandle<D, Self>, mut net: NetMutHandle<'_, D, Self>,
msg: NetMessage<D>, msg: NetMessage<D>,
rng: &mut R, rng: &mut R,
) -> Result<CpStep<D>, CrankError<D>> { ) -> Result<CpStep<D>, CrankError<D>> {
@ -407,7 +407,7 @@ where
D::Output: Clone, D::Output: Clone,
{ {
#[inline] #[inline]
fn pre_crank<R: Rng>(&mut self, mut net: NetMutHandle<D, Self>, _rng: &mut R) { fn pre_crank<R: Rng>(&mut self, mut net: NetMutHandle<'_, D, Self>, _rng: &mut R) {
// Message are sorted by NodeID on each step. // Message are sorted by NodeID on each step.
net.sort_messages_by(|a, b| a.to.cmp(&b.to)) net.sort_messages_by(|a, b| a.to.cmp(&b.to))
} }
@ -434,7 +434,7 @@ where
D::Output: Clone, D::Output: Clone,
{ {
#[inline] #[inline]
fn pre_crank<R: Rng>(&mut self, mut net: NetMutHandle<D, Self>, rng: &mut R) { fn pre_crank<R: Rng>(&mut self, mut net: NetMutHandle<'_, D, Self>, rng: &mut R) {
let l = net.0.messages_len(); let l = net.0.messages_len();
if l > 0 { if l > 0 {
net.swap_messages(0, rng.gen_range(0, l)); net.swap_messages(0, rng.gen_range(0, l));

View File

@ -66,7 +66,7 @@ impl<D> Display for CrankError<D>
where where
D: ConsensusProtocol, D: ConsensusProtocol,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
CrankError::HandleInput(err) => { CrankError::HandleInput(err) => {
write!(f, "The algorithm could not process input: {:?}", err) write!(f, "The algorithm could not process input: {:?}", err)
@ -122,7 +122,7 @@ impl<D> Debug for CrankError<D>
where where
D: ConsensusProtocol, D: ConsensusProtocol,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
CrankError::HandleInput(err) => { CrankError::HandleInput(err) => {
f.debug_struct("HandleInput").field("err", err).finish() f.debug_struct("HandleInput").field("err", err).finish()
@ -170,7 +170,7 @@ impl<D> failure::Fail for CrankError<D>
where where
D: ConsensusProtocol + 'static, D: ConsensusProtocol + 'static,
{ {
fn cause(&self) -> Option<&failure::Fail> { fn cause(&self) -> Option<&dyn failure::Fail> {
match self { match self {
CrankError::HandleInput(err) | CrankError::HandleInputAll(err) => Some(err), CrankError::HandleInput(err) | CrankError::HandleInputAll(err) => Some(err),
CrankError::HandleMessage { err, .. } => Some(err), CrankError::HandleMessage { err, .. } => Some(err),

View File

@ -82,7 +82,7 @@ impl<D> fmt::Debug for Node<D>
where where
D: ConsensusProtocol, D: ConsensusProtocol,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Node") f.debug_struct("Node")
.field("algorithm", &"yes") .field("algorithm", &"yes")
.field("is_faulty", &self.is_faulty) .field("is_faulty", &self.is_faulty)
@ -317,7 +317,7 @@ where
/// Number of faulty nodes in the network. /// Number of faulty nodes in the network.
num_faulty: usize, num_faulty: usize,
/// Dist-algorithm constructor function. /// Dist-algorithm constructor function.
cons: Option<Box<Fn(NewNodeInfo<D>) -> (D, CpStep<D>)>>, cons: Option<Box<dyn Fn(NewNodeInfo<D>) -> (D, CpStep<D>)>>,
/// Network adversary. /// Network adversary.
adversary: Option<A>, adversary: Option<A>,
/// Trace-enabling flag. `None` means use environment. /// Trace-enabling flag. `None` means use environment.
@ -338,7 +338,7 @@ where
D: ConsensusProtocol, D: ConsensusProtocol,
A: fmt::Debug, A: fmt::Debug,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("NetBuilder") f.debug_struct("NetBuilder")
.field("node_ids", &()) .field("node_ids", &())
.field("num_faulty", &self.num_faulty) .field("num_faulty", &self.num_faulty)

View File

@ -142,7 +142,7 @@ pub struct MessageWithSender<D: ConsensusProtocol> {
// The Debug implementation cannot be derived automatically, possibly due to a compiler bug. For // The Debug implementation cannot be derived automatically, possibly due to a compiler bug. For
// this reason, it is implemented manually here. // this reason, it is implemented manually here.
impl<D: ConsensusProtocol> fmt::Debug for MessageWithSender<D> { impl<D: ConsensusProtocol> fmt::Debug for MessageWithSender<D> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
"MessageWithSender {{ sender: {:?}, tm: {:?} }}", "MessageWithSender {{ sender: {:?}, tm: {:?} }}",