Replace manual Debug impl with educe in tor-guardmgr

This commit is contained in:
Ian Jackson 2022-03-02 14:47:50 +00:00
parent f474a583f1
commit b2d8c14c90
3 changed files with 11 additions and 11 deletions

2
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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<UnboundedSender<daemon::Msg>>,
}
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<daemon::Msg>) -> Self {