From 4826d757ace0f57200398db393d8cb52d8da4539 Mon Sep 17 00:00:00 2001 From: trinity-1686a Date: Sat, 12 Mar 2022 11:10:00 +0100 Subject: [PATCH] use downcast-rs instead of our own AsAny --- Cargo.lock | 13 +++++++++++++ crates/tor-circmgr/Cargo.toml | 1 + crates/tor-circmgr/src/usage.rs | 18 +++--------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 178916a42..4602a207e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -869,6 +869,8 @@ dependencies = [ [[package]] name = "derive_builder" version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd8db2d51ce241afb74f9e5cf9482de69c4b77657c2ddaf78993eda8ce2ce8c" dependencies = [ "derive_builder_macro", ] @@ -876,6 +878,8 @@ dependencies = [ [[package]] name = "derive_builder_core" version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf03b84d76c5bb011d983c17e2675ab49f5498f121bf1ceae5b5855b4a4dddd" dependencies = [ "darling", "proc-macro2", @@ -886,6 +890,8 @@ dependencies = [ [[package]] name = "derive_builder_macro" version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cae44c47bca4fd1eaeda52b3d0eecb664ddcbc0d4e7b238bae7ec2c931646c0" dependencies = [ "derive_builder_core", "syn", @@ -974,6 +980,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + [[package]] name = "easy-parallel" version = "3.2.0" @@ -3218,6 +3230,7 @@ dependencies = [ "async-trait", "bounded-vec-deque", "derive_builder", + "downcast-rs", "educe", "futures", "futures-await-test", diff --git a/crates/tor-circmgr/Cargo.toml b/crates/tor-circmgr/Cargo.toml index f9b573979..ef60886fb 100644 --- a/crates/tor-circmgr/Cargo.toml +++ b/crates/tor-circmgr/Cargo.toml @@ -34,6 +34,7 @@ tor-rtcompat = { path="../tor-rtcompat", version = "0.1.0"} async-trait = "0.1.2" bounded-vec-deque = "0.1" derive_builder = "0.11" +downcast-rs = "1.2.0" educe = "0.4.6" futures = "0.3.14" humantime-serde = "1.1.1" diff --git a/crates/tor-circmgr/src/usage.rs b/crates/tor-circmgr/src/usage.rs index 314b79476..4b14dbe62 100644 --- a/crates/tor-circmgr/src/usage.rs +++ b/crates/tor-circmgr/src/usage.rs @@ -1,5 +1,6 @@ //! Code related to tracking what activities a circuit can be used for. +use downcast_rs::{impl_downcast, Downcast}; use rand::Rng; use serde::{Deserialize, Serialize}; use std::fmt::{self, Display}; @@ -100,27 +101,14 @@ impl Display for TargetPorts { } } -use std::any::Any; - /// TODO -pub trait AsAny { - /// TODO - fn as_any(&self) -> &dyn Any; -} - -impl AsAny for T { - fn as_any(&self) -> &dyn Any { - self - } -} - -/// TODO -pub trait Isolation: AsAny + std::fmt::Debug + Send + Sync + 'static { +pub trait Isolation: Downcast + std::fmt::Debug + Send + Sync + 'static { /// TODO fn isolated(&self, other: &dyn Isolation) -> bool; /// TODO fn join(&self, other: &dyn Isolation) -> JoinResult; } +impl_downcast!(Isolation); impl Isolation for T { fn isolated(&self, other: &dyn Isolation) -> bool {