Commit eb66d0af authored by Ian Jackson's avatar Ian Jackson 💬
Browse files

Merge branch 'derive-traits' into 'main'

Tidy up many open-coded trait impls

See merge request !374
parents 2a7915e6 e9f8ddfb
Loading
Loading
Loading
Loading
+1 −11
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ use std::fmt::{Debug, Display, Error as FmtError, Formatter};
/// fails, use [`RetryError::push()`] to add a new error to the list
/// of errors.  If the operation fails too many times, you can use
/// RetryError as an [`Error`] itself.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RetryError<E> {
    /// The operation we were trying to do.
    doing: String,
@@ -191,16 +191,6 @@ impl Attempt {
    }
}

impl<E: Clone> Clone for RetryError<E> {
    fn clone(&self) -> RetryError<E> {
        RetryError {
            doing: self.doing.clone(),
            errors: self.errors.clone(),
            n_errors: self.n_errors,
        }
    }
}

impl<E, T> Extend<T> for RetryError<E>
where
    T: Into<E>,
+1 −6
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ impl ChanMsg {
/// channel, or as a "keep-alive".
///
/// The correct response to a padding cell is to drop it and do nothing.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct Padding {}
impl Padding {
@@ -168,11 +168,6 @@ impl Padding {
        Padding {}
    }
}
impl Default for Padding {
    fn default() -> Self {
        Padding::new()
    }
}
impl Body for Padding {
    fn into_message(self) -> ChanMsg {
        ChanMsg::Padding(self)
+3 −10
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ use futures::stream::{FuturesUnordered, StreamExt};
use futures::task::SpawnExt;
use std::collections::HashMap;
use std::convert::TryInto;
use std::fmt::{self, Debug};
use std::fmt::Debug;
use std::hash::Hash;
use std::panic::AssertUnwindSafe;
use std::sync::{self, Arc, Weak};
@@ -383,6 +383,7 @@ impl<B: AbstractCircBuilder> PendingRequest<B> {

/// An entry for an under-construction in-progress circuit tracked by
/// an `AbstractCircMgr`.
#[derive(Debug)]
struct PendingEntry<B: AbstractCircBuilder> {
    /// Specification that this circuit will support, if every pending
    /// request that is waiting for it is attached to it.
@@ -448,6 +449,7 @@ impl<B: AbstractCircBuilder> PendingEntry<B> {

/// Wrapper type to represent the state between planning to build a
/// circuit and constructing it.
#[derive(Debug)]
struct CircBuildPlan<B: AbstractCircBuilder> {
    /// The Plan object returned by [`AbstractCircBuilder::plan_circuit`].
    plan: B::Plan,
@@ -457,15 +459,6 @@ struct CircBuildPlan<B: AbstractCircBuilder> {
    pending: Arc<PendingEntry<B>>,
}

impl<B: AbstractCircBuilder> Debug for CircBuildPlan<B> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("CircBuildPlan")
            .field("plan", &self.plan)
            .field("sender", &self.sender)
            .finish_non_exhaustive()
    }
}

/// The inner state of an [`AbstractCircMgr`].
struct CircList<B: AbstractCircBuilder> {
    /// A map from circuit ID to [`OpenEntry`] values for all managed
+1 −7
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ use std::sync::{Arc, RwLock};
///
/// Internally, this is just a `RwLock<Arc<T>>`; this type just defines some
/// convenience wrappers for it.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct MutCfg<T> {
    /// The interior configuration object.
    cfg: RwLock<Arc<T>>,
@@ -55,12 +55,6 @@ impl<T> MutCfg<T> {
    }
}

impl<T: Default> Default for MutCfg<T> {
    fn default() -> Self {
        MutCfg::new(T::default())
    }
}

impl<T> From<T> for MutCfg<T> {
    fn from(config: T) -> MutCfg<T> {
        MutCfg::new(config)
+6 −30
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ impl Requestable for ConsensusRequest {
}

/// A request for one or more authority certificates.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct AuthCertRequest {
    /// The identity/signing keys of the certificates we want.
    ids: Vec<AuthCertKeyIds>,
@@ -162,7 +162,7 @@ pub struct AuthCertRequest {
impl AuthCertRequest {
    /// Create a new request, asking for no authority certificates.
    pub fn new() -> Self {
        AuthCertRequest { ids: Vec::new() }
        AuthCertRequest::default()
    }

    /// Add `ids` to the list of certificates we're asking for.
@@ -176,12 +176,6 @@ impl AuthCertRequest {
    }
}

impl Default for AuthCertRequest {
    fn default() -> Self {
        Self::new()
    }
}

impl Requestable for AuthCertRequest {
    fn make_request(&self) -> Result<http::Request<()>> {
        let mut ids = self.ids.clone();
@@ -227,7 +221,7 @@ impl FromIterator<AuthCertKeyIds> for AuthCertRequest {
}

/// A request for one or more microdescriptors
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct MicrodescRequest {
    /// The SHA256 digests of the microdescriptors we want.
    digests: Vec<MdDigest>,
@@ -236,9 +230,7 @@ pub struct MicrodescRequest {
impl MicrodescRequest {
    /// Construct a request for no microdescriptors.
    pub fn new() -> Self {
        MicrodescRequest {
            digests: Vec::new(),
        }
        MicrodescRequest::default()
    }
    /// Add `d` to the list of microdescriptors we want to request.
    pub fn push(&mut self, d: MdDigest) {
@@ -251,12 +243,6 @@ impl MicrodescRequest {
    }
}

impl Default for MicrodescRequest {
    fn default() -> Self {
        Self::new()
    }
}

impl Requestable for MicrodescRequest {
    fn make_request(&self) -> Result<http::Request<()>> {
        // TODO: require that self.digests is nonempty.
@@ -296,7 +282,7 @@ impl FromIterator<MdDigest> for MicrodescRequest {
}

/// A request for one, many or all router descriptors.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
#[cfg(feature = "routerdesc")]
pub struct RouterDescRequest {
    /// If this is set, we just ask for all the descriptors.
@@ -307,13 +293,6 @@ pub struct RouterDescRequest {
    digests: Vec<RdDigest>,
}

#[cfg(feature = "routerdesc")]
impl Default for RouterDescRequest {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(feature = "routerdesc")]
impl RouterDescRequest {
    /// Construct a request for all router descriptors.
@@ -325,10 +304,7 @@ impl RouterDescRequest {
    }
    /// Construct a new empty request.
    pub fn new() -> Self {
        RouterDescRequest {
            all_descriptors: false,
            digests: Vec::new(),
        }
        RouterDescRequest::default()
    }
    /// Add `d` to the list of digests we want to request.
    pub fn push(&mut self, d: RdDigest) {
Loading