From ea03cc408494ba1c4992399f97978a1d964d6774 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 2 Mar 2022 15:13:48 +0000 Subject: [PATCH] Replace manual Clone impl with educe in tor-rtcompat --- Cargo.lock | 1 + crates/tor-rtcompat/Cargo.toml | 1 + crates/tor-rtcompat/src/compound.rs | 13 +++---------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61248df56..f2b6decb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3492,6 +3492,7 @@ dependencies = [ "async-std", "async-trait", "async_executors", + "educe", "futures", "native-tls", "pin-project", diff --git a/crates/tor-rtcompat/Cargo.toml b/crates/tor-rtcompat/Cargo.toml index 9cbd48d35..3ff74c3e1 100644 --- a/crates/tor-rtcompat/Cargo.toml +++ b/crates/tor-rtcompat/Cargo.toml @@ -25,6 +25,7 @@ rustls = [ "rustls-crate", "async-rustls", "x509-signature" ] async_executors = { version = "0.4", default_features = false } async-trait = "0.1.2" +educe = "0.4.6" futures = "0.3.14" pin-project = "1" native-tls-crate = { package = "native-tls", version = "0.2", optional = true } diff --git a/crates/tor-rtcompat/src/compound.rs b/crates/tor-rtcompat/src/compound.rs index 44f019657..f51636580 100644 --- a/crates/tor-rtcompat/src/compound.rs +++ b/crates/tor-rtcompat/src/compound.rs @@ -5,6 +5,7 @@ use std::{net::SocketAddr, sync::Arc, time::Duration}; use crate::traits::*; use async_trait::async_trait; +use educe::Educe; use futures::{future::FutureObj, task::Spawn}; use std::io::Result as IoResult; @@ -18,6 +19,8 @@ use std::io::Result as IoResult; /// You can use this structure to create new runtimes in two ways: either by /// overriding a single part of an existing runtime, or by building an entirely /// new runtime from pieces. +#[derive(Educe)] +#[educe(Clone)] // #[derive(Clone)] wrongly infers Clone bounds on the generic parameters pub struct CompoundRuntime { /// The actual collection of Runtime objects. /// @@ -26,16 +29,6 @@ pub struct CompoundRuntime { inner: Arc>, } -// We have to provide this ourselves, since derive(Clone) wrongly infers a -// `where S: Clone` bound (from the generic argument). -impl Clone for CompoundRuntime { - fn clone(&self) -> Self { - Self { - inner: Arc::clone(&self.inner), - } - } -} - /// A collection of objects implementing that traits that make up a [`Runtime`] struct Inner { /// A `Spawn` and `BlockOn` implementation.