Skip to content

Commit 55906db

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 55906db

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-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: 17 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,19 @@ where
214213
Poll::Ready(None) | Poll::Pending => Poll::Pending,
215214
}
216215
}
216+
217+
218+
219+
220+
impl<St1, St2, Clos, State> fmt::Debug for SelectWithStrategy<St1, St2, Clos, State>
221+
where
222+
St1: fmt::Debug,
223+
St2: fmt::Debug,
224+
{
225+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226+
f.debug_struct("SelectWithStrategy")
227+
.field("stream1", &self.stream1)
228+
.field("stream2", &self.stream2)
229+
.finish()
230+
}
231+
}

0 commit comments

Comments
 (0)