Skip to content

Commit

Permalink
Give SelectWithStrategy a custom fmt::Debug impl.
Browse files Browse the repository at this point in the history
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 } } }`
  • Loading branch information
najamelan committed Jun 17, 2021
1 parent 34c4a00 commit e8a17f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions futures-util/src/stream/select.rs
Expand Up @@ -7,6 +7,7 @@ use pin_project_lite::pin_project;

pin_project! {
/// Stream for the [`select()`] function.
#[derive(Debug)]
#[must_use = "streams do nothing unless polled"]
pub struct Select<St1, St2> {
#[pin]
Expand Down
18 changes: 16 additions & 2 deletions futures-util/src/stream/select_with_strategy.rs
@@ -1,6 +1,6 @@
use super::assert_stream;
use crate::stream::{Fuse, StreamExt};
use core::pin::Pin;
use core::{fmt, pin::Pin};
use futures_core::stream::{FusedStream, Stream};
use futures_core::task::{Context, Poll};
use pin_project_lite::pin_project;
Expand Down Expand Up @@ -36,7 +36,6 @@ impl Default for PollNext {

pin_project! {
/// Stream for the [`select_with_strategy()`] function. See function docs for details.
#[derive(Debug)]
#[must_use = "streams do nothing unless polled"]
pub struct SelectWithStrategy<St1, St2, Clos, State> {
#[pin]
Expand Down Expand Up @@ -214,3 +213,18 @@ where
Poll::Ready(None) | Poll::Pending => Poll::Pending,
}
}

impl<St1, St2, Clos, State> fmt::Debug for SelectWithStrategy<St1, St2, Clos, State>
where
St1: fmt::Debug,
St2: fmt::Debug,
State: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SelectWithStrategy")
.field("stream1", &self.stream1)
.field("stream2", &self.stream2)
.field("state", &self.state)
.finish()
}
}

0 comments on commit e8a17f9

Please sign in to comment.