Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion tokio-util/src/task/abort_on_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::{
///
/// [aborts]: tokio::task::JoinHandle::abort
#[must_use = "Dropping the handle aborts the task immediately"]
#[derive(Debug)]
pub struct AbortOnDropHandle<T>(JoinHandle<T>);

impl<T> Drop for AbortOnDropHandle<T> {
Expand Down Expand Up @@ -58,6 +57,14 @@ impl<T> AbortOnDropHandle<T> {
}
}

impl<T> std::fmt::Debug for AbortOnDropHandle<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AbortOnDropHandle")
.field("id", &self.0.id())
.finish()
}
}

impl<T> Future for AbortOnDropHandle<T> {
type Output = Result<T, JoinError>;

Expand All @@ -71,3 +78,18 @@ impl<T> AsRef<JoinHandle<T>> for AbortOnDropHandle<T> {
&self.0
}
}

#[cfg(test)]
mod tests {
use super::*;

/// A simple type that does not implement [`std::fmt::Debug`].
struct NotDebug;

fn is_debug<T: std::fmt::Debug>() {}

#[test]
fn assert_debug() {
is_debug::<AbortOnDropHandle<NotDebug>>();
}
}
24 changes: 23 additions & 1 deletion tokio-util/src/task/join_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use tokio::{
///
/// When the [`JoinQueue`] is dropped, all tasks in the [`JoinQueue`] are
/// immediately aborted.
#[derive(Debug)]
pub struct JoinQueue<T>(VecDeque<AbortOnDropHandle<T>>);

impl<T> JoinQueue<T> {
Expand Down Expand Up @@ -379,6 +378,14 @@ impl<T> JoinQueue<T> {
}
}

impl<T> std::fmt::Debug for JoinQueue<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_list()
.entries(self.0.iter().map(|jh| JoinHandle::id(jh.as_ref())))
.finish()
}
}

impl<T> Default for JoinQueue<T> {
fn default() -> Self {
Self::new()
Expand All @@ -401,3 +408,18 @@ where
set
}
}

#[cfg(test)]
mod tests {
use super::*;

/// A simple type that does not implement [`std::fmt::Debug`].
struct NotDebug;

fn is_debug<T: std::fmt::Debug>() {}

#[test]
fn assert_debug() {
is_debug::<JoinQueue<NotDebug>>();
}
}