From 2a894f96f2a14e19074c523970714ccbd167d9a2 Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Fri, 29 Mar 2024 07:51:21 -0700 Subject: [PATCH] Simplify fmt::Debug representations (#26) The Debug renderings of the Watch and Signal types are quite verbose, dumping the state of the internal watch (which isn't really useful to) callers. This change minimizes the Debug output to just the type names and bumps the package version in anticipation of the next release. --- Cargo.toml | 2 +- src/lib.rs | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 17460e9..73d1379 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drain" -version = "0.1.1" +version = "0.1.2" authors = ["Linkerd Developers "] license = "Apache-2.0" edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index b2f1fd6..aee4fad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,6 @@ pub fn channel() -> (Signal, Watch) { enum Never {} /// Send a drain command to all watchers. -#[derive(Debug)] pub struct Signal { drained_rx: mpsc::Receiver, signal_tx: watch::Sender<()>, @@ -41,14 +40,14 @@ pub struct Signal { /// /// All `Watch` instances must be dropped for a `Signal::signal` call to /// complete. -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct Watch { drained_tx: mpsc::Sender, signal_rx: watch::Receiver<()>, } #[must_use = "ReleaseShutdown should be dropped explicitly to release the runtime"] -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct ReleaseShutdown(mpsc::Sender); // === impl Signal === @@ -74,6 +73,12 @@ impl Signal { } } +impl std::fmt::Debug for Signal { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Signal").finish_non_exhaustive() + } +} + // === impl Watch === impl Watch { @@ -117,6 +122,12 @@ impl Watch { } } +impl std::fmt::Debug for Watch { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Watch").finish_non_exhaustive() + } +} + impl ReleaseShutdown { /// Releases shutdown after `future` completes. pub async fn release_after(self, future: F) -> F::Output { @@ -125,6 +136,11 @@ impl ReleaseShutdown { res } } +impl std::fmt::Debug for ReleaseShutdown { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("ReleaseShutdown").finish_non_exhaustive() + } +} #[cfg(test)] mod tests {