From 89074a1326f0473b65f12ba1f2131e5e222721c8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 2 Mar 2022 17:54:59 +0000 Subject: [PATCH] Replace manual Default and new with std derive in tor-proto --- crates/tor-proto/src/channel.rs | 9 ++------- crates/tor-protover/src/lib.rs | 13 ++----------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/crates/tor-proto/src/channel.rs b/crates/tor-proto/src/channel.rs index 9834216e2..13ee5845f 100644 --- a/crates/tor-proto/src/channel.rs +++ b/crates/tor-proto/src/channel.rs @@ -189,6 +189,7 @@ impl Sink for Channel { } /// Structure for building and launching a Tor channel. +#[derive(Default)] pub struct ChannelBuilder { /// If present, a description of the address we're trying to connect to, /// to be used in log messages. @@ -201,7 +202,7 @@ pub struct ChannelBuilder { impl ChannelBuilder { /// Construct a new ChannelBuilder. pub fn new() -> Self { - ChannelBuilder { target: None } + ChannelBuilder::default() } /// Set the declared target address of this channel. @@ -228,12 +229,6 @@ impl ChannelBuilder { } } -impl Default for ChannelBuilder { - fn default() -> Self { - Self::new() - } -} - impl Channel { /// Construct a channel and reactor. /// diff --git a/crates/tor-protover/src/lib.rs b/crates/tor-protover/src/lib.rs index af74621c7..70896460a 100644 --- a/crates/tor-protover/src/lib.rs +++ b/crates/tor-protover/src/lib.rs @@ -157,7 +157,7 @@ struct SubprotocolEntry { /// use tor_protover::Protocols; /// let p: Result = "Link=1-3 LinkAuth=2-3 Relay=1-2".parse(); /// ``` -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct Protocols { /// A mapping from protocols' integer encodings to bit-vectors. recognized: [u64; N_RECOGNIZED], @@ -168,10 +168,7 @@ pub struct Protocols { impl Protocols { /// Return a new empty set of protocol versions. pub fn new() -> Self { - Protocols { - recognized: [0_u64; N_RECOGNIZED], - unrecognized: Vec::new(), - } + Protocols::default() } /// Helper: return true iff this protocol set contains the /// version `ver` of the protocol represented by the integer `proto`. @@ -267,12 +264,6 @@ impl Protocols { } } -impl Default for Protocols { - fn default() -> Self { - Protocols::new() - } -} - /// An error representing a failure to parse a set of protocol versions. #[derive(Error, Debug, PartialEq, Eq, Clone)] #[non_exhaustive]