Skip to content

Commit

Permalink
refac(console): remove useless Pin::new() on streaming (#485)
Browse files Browse the repository at this point in the history
It seems we don't need to `Pin` it here.

For the `next` API:
```rust
    /// Creates a future that resolves to the next item in the stream.
    ///
    /// Note that because `next` doesn't take ownership over the stream,
    /// the [`Stream`] type must be [`Unpin`]. If you want to use `next` with a
    /// [`!Unpin`](Unpin) stream, you'll first have to pin the stream. This can
    /// be done by boxing the stream using [`Box::pin`] or
    /// pinning it to the stack using the `pin_mut!` macro from the `pin_utils`
    /// crate.
```

But here it is an `Unpin` stream, so we don't need to pin it.
  • Loading branch information
Rustin170506 authored Oct 30, 2023
1 parent df4457f commit 528a4ca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tokio-console/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use console_api::instrument::{
};
use console_api::tasks::TaskDetails;
use futures::stream::StreamExt;
use std::{error::Error, pin::Pin, time::Duration};
use std::{error::Error, time::Duration};
#[cfg(unix)]
use tokio::net::UnixStream;
use tonic::{
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Connection {
pub async fn next_update(&mut self) -> Update {
loop {
match self.state {
State::Connected { ref mut stream, .. } => match Pin::new(stream).next().await {
State::Connected { ref mut stream, .. } => match stream.next().await {
Some(Ok(update)) => return update,
Some(Err(status)) => {
tracing::warn!(%status, "error from stream");
Expand Down

0 comments on commit 528a4ca

Please sign in to comment.