impl Debug for various internal types
I wanted this while debugging something. The ad-hoc impl Debug with f.debug_struct is getting repetitive and I've already perpetrated one copy-paste mistake. We should consider using something like the `educe` crate's Clone.
This commit is contained in:
parent
c98a2f6f62
commit
6b615b4766
|
@ -7,6 +7,7 @@ use crate::{DirInfo, Error, Result};
|
|||
use async_trait::async_trait;
|
||||
use futures::future::OptionFuture;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt::{self, Debug};
|
||||
use std::sync::Arc;
|
||||
use tor_error::internal;
|
||||
use tor_proto::circuit::{CircParameters, ClientCirc};
|
||||
|
@ -41,6 +42,17 @@ pub(crate) struct Plan {
|
|||
guard_usable: Option<tor_guardmgr::GuardUsable>,
|
||||
}
|
||||
|
||||
impl Debug for Plan {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("Planr")
|
||||
.field("final_spec", &self.final_spec)
|
||||
.field("path", &self.path)
|
||||
.field("params", &self.params)
|
||||
.field("guard_status", &self.guard_status)
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl MockablePlan for Plan {}
|
||||
|
||||
#[async_trait]
|
||||
|
|
|
@ -37,7 +37,7 @@ use futures::stream::{FuturesUnordered, StreamExt};
|
|||
use futures::task::SpawnExt;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::{self, Debug};
|
||||
use std::hash::Hash;
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::sync::{self, Arc, Weak};
|
||||
|
@ -160,7 +160,7 @@ pub(crate) trait MockablePlan {
|
|||
pub(crate) trait AbstractCircBuilder: Send + Sync {
|
||||
/// The specification type describing what operations circuits can
|
||||
/// be used for.
|
||||
type Spec: AbstractSpec + Send + Sync;
|
||||
type Spec: AbstractSpec + Debug + Send + Sync;
|
||||
/// The circuit type that this builder knows how to build.
|
||||
type Circ: AbstractCirc + Send + Sync;
|
||||
/// An opaque type describing how a given circuit will be built.
|
||||
|
@ -170,7 +170,7 @@ pub(crate) trait AbstractCircBuilder: Send + Sync {
|
|||
// But I don't think that rust can do that.
|
||||
|
||||
// HACK(eta): I don't like the fact that `MockablePlan` is necessary here.
|
||||
type Plan: Send + MockablePlan;
|
||||
type Plan: Send + Debug + MockablePlan;
|
||||
|
||||
// TODO: I'd like to have a Dir type here to represent
|
||||
// create::DirInfo, but that would need to be parameterized too,
|
||||
|
@ -457,6 +457,15 @@ 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("CircBuildPlna")
|
||||
.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
|
||||
|
|
|
@ -87,7 +87,7 @@ impl<'a> TorPath<'a> {
|
|||
}
|
||||
|
||||
/// A path composed entirely of owned components.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum OwnedPath {
|
||||
/// A path where we only know how to make circuits via CREATE_FAST.
|
||||
ChannelOnly(OwnedChanTarget),
|
||||
|
|
|
@ -14,6 +14,7 @@ use futures::{
|
|||
Future,
|
||||
};
|
||||
use pin_project::pin_project;
|
||||
use std::fmt::{self, Debug};
|
||||
use std::pin::Pin;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::task::{Context, Poll};
|
||||
|
@ -121,6 +122,16 @@ pub struct GuardMonitor {
|
|||
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 {
|
||||
|
|
Loading…
Reference in New Issue