Skip to content

Commit

Permalink
Simplify fmt::Debug representations (#26)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olix0r authored Mar 29, 2024
1 parent f40c6ce commit 2a894f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drain"
version = "0.1.1"
version = "0.1.2"
authors = ["Linkerd Developers <[email protected]>"]
license = "Apache-2.0"
edition = "2018"
Expand Down
22 changes: 19 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Never>,
signal_tx: watch::Sender<()>,
Expand All @@ -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<Never>,
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<Never>);

// === impl Signal ===
Expand All @@ -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 {
Expand Down Expand Up @@ -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<F: Future>(self, future: F) -> F::Output {
Expand All @@ -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 {
Expand Down

0 comments on commit 2a894f9

Please sign in to comment.