Skip to content

Commit 2df5523

Browse files
committed
Give SelectWithStrategy a custom fmt::Debug impl.
This allows not to print the closure and give `Select` a derive impl. The result for `Select` looks like: `Select { inner: SelectWithStrategy { stream1: Fuse { stream: Repeat { item: 1 }, done: false }, stream2: Fuse { stream: Repeat { item: 2 }, done: false } } }`
1 parent 34c4a00 commit 2df5523

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

futures-util/src/stream/select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use pin_project_lite::pin_project;
77

88
pin_project! {
99
/// Stream for the [`select()`] function.
10+
#[derive(Debug)]
1011
#[must_use = "streams do nothing unless polled"]
1112
pub struct Select<St1, St2> {
1213
#[pin]

futures-util/src/stream/select_with_strategy.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::assert_stream;
22
use crate::stream::{Fuse, StreamExt};
3-
use core::pin::Pin;
3+
use core::{fmt, pin::Pin};
44
use futures_core::stream::{FusedStream, Stream};
55
use futures_core::task::{Context, Poll};
66
use pin_project_lite::pin_project;
@@ -36,7 +36,6 @@ impl Default for PollNext {
3636

3737
pin_project! {
3838
/// Stream for the [`select_with_strategy()`] function. See function docs for details.
39-
#[derive(Debug)]
4039
#[must_use = "streams do nothing unless polled"]
4140
pub struct SelectWithStrategy<St1, St2, Clos, State> {
4241
#[pin]
@@ -214,3 +213,16 @@ where
214213
Poll::Ready(None) | Poll::Pending => Poll::Pending,
215214
}
216215
}
216+
217+
impl<St1, St2, Clos, State> fmt::Debug for SelectWithStrategy<St1, St2, Clos, State>
218+
where
219+
St1: fmt::Debug,
220+
St2: fmt::Debug,
221+
{
222+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
223+
f.debug_struct("SelectWithStrategy")
224+
.field("stream1", &self.stream1)
225+
.field("stream2", &self.stream2)
226+
.finish()
227+
}
228+
}

0 commit comments

Comments
 (0)