From b2d8c14c905a32fad684cb5389bfc35e5cd8a924 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 2 Mar 2022 14:47:50 +0000 Subject: [PATCH] Replace manual Debug impl with educe in tor-guardmgr --- Cargo.lock | 2 ++ crates/tor-guardmgr/Cargo.toml | 2 ++ crates/tor-guardmgr/src/pending.rs | 18 +++++++----------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f77b60ad6..934e2e4ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3303,6 +3303,7 @@ name = "tor-guardmgr" version = "0.1.0" dependencies = [ "derive_builder", + "educe", "futures", "humantime-serde", "itertools", @@ -3311,6 +3312,7 @@ dependencies = [ "retain_mut", "serde", "thiserror", + "tor-bytes", "tor-config", "tor-error", "tor-linkspec", diff --git a/crates/tor-guardmgr/Cargo.toml b/crates/tor-guardmgr/Cargo.toml index 65161d2cb..140cc7e11 100644 --- a/crates/tor-guardmgr/Cargo.toml +++ b/crates/tor-guardmgr/Cargo.toml @@ -18,6 +18,7 @@ default = [] testing = [] [dependencies] +tor-bytes = { path="../tor-bytes", version = "0.1.0"} tor-config = { path="../tor-config", version = "0.1.0"} tor-error = { path="../tor-error", version = "0.1.0"} tor-netdir = { path="../tor-netdir", version = "0.1.0"} @@ -29,6 +30,7 @@ tor-rtcompat = { path="../tor-rtcompat", version = "0.1.0"} tor-units = { path="../tor-units", version = "0.1.0"} derive_builder = "0.10" +educe = "0.4.6" futures = "0.3.14" humantime-serde = "1" itertools = "0.10.1" diff --git a/crates/tor-guardmgr/src/pending.rs b/crates/tor-guardmgr/src/pending.rs index cc6222f76..31690526f 100644 --- a/crates/tor-guardmgr/src/pending.rs +++ b/crates/tor-guardmgr/src/pending.rs @@ -9,17 +9,20 @@ //! handled via [`GuardUsable`]. use crate::{daemon, GuardId}; +use educe::Educe; use futures::{ channel::{mpsc::UnboundedSender, oneshot}, Future, }; use pin_project::pin_project; -use std::fmt::{self, Debug}; +use std::fmt::Debug; use std::pin::Pin; use std::sync::atomic::{AtomicU64, Ordering}; use std::task::{Context, Poll}; use std::time::Instant; +use tor_bytes::skip_fmt; + /// A future used to see if we have "permission" to use a guard. /// /// For efficiency, the [`GuardMgr`](crate::GuardMgr) implementation sometimes gives @@ -101,6 +104,8 @@ pub enum GuardStatus { /// The `GuardMgr` needs to know about these statuses, so that it can tell /// whether the guard is running or not. #[must_use = "You need to report the status of any guard that you asked for"] +#[derive(Educe)] +#[educe(Debug)] pub struct GuardMonitor { /// The Id that we're going to report about. id: RequestId, @@ -119,19 +124,10 @@ pub struct GuardMonitor { /// TODO: This doesn't really need to be an Option, but we use None /// here to indicate that we've already used the sender, and it can't /// be used again. + #[educe(Debug(method = "skip_fmt"))] snd: Option>, } -impl Debug for GuardMonitor { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("GuardMonitor") - .field("id", &self.id) - .field("pending_status", &self.pending_status) - .field("ignore_indeterminate", &self.ignore_indeterminate) - .finish_non_exhaustive() - } -} - impl GuardMonitor { /// Create a new GuardMonitor object. pub(crate) fn new(id: RequestId, snd: UnboundedSender) -> Self {