From 7dde679dde44b37d66677e651233497937bd3058 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 19 Dec 2023 09:05:57 +0800 Subject: [PATCH] refactor: Remove never used Stream poll_reset API Signed-off-by: Xuanwo --- core/src/raw/http_util/multipart.rs | 24 ----- core/src/raw/oio/buf/chunked_bytes.rs | 7 -- core/src/raw/oio/cursor.rs | 5 - core/src/raw/oio/stream/api.rs | 94 ------------------- core/src/raw/oio/stream/into_stream.rs | 7 -- .../raw/oio/stream/into_stream_from_reader.rs | 7 -- 6 files changed, 144 deletions(-) diff --git a/core/src/raw/http_util/multipart.rs b/core/src/raw/http_util/multipart.rs index a6c6f765278..5e38a48c462 100644 --- a/core/src/raw/http_util/multipart.rs +++ b/core/src/raw/http_util/multipart.rs @@ -204,14 +204,6 @@ impl Stream for MultipartStream { Poll::Ready(None) } - - /// It's possible to implement reset by calling stream's `poll_reset`. - fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Err(Error::new( - ErrorKind::Unsupported, - "MultipartStream doesn't support reset yet", - ))) - } } /// Part is a trait for multipart part. @@ -344,14 +336,6 @@ impl Stream for FormDataPartStream { Poll::Ready(None) } - - /// It's possible to implement reset by calling stream's `poll_reset`. - fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Err(Error::new( - ErrorKind::Unsupported, - "FormDataPartStream doesn't support reset yet", - ))) - } } /// MixedPart is a builder for multipart/mixed part. @@ -698,14 +682,6 @@ impl Stream for MixedPartStream { Poll::Ready(None) } - - /// It's possible to implement reset by calling stream's `poll_reset`. - fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Err(Error::new( - ErrorKind::Unsupported, - "MixedPartStream doesn't support reset yet", - ))) - } } #[cfg(test)] diff --git a/core/src/raw/oio/buf/chunked_bytes.rs b/core/src/raw/oio/buf/chunked_bytes.rs index 73e94b44c9b..95ca55a219d 100644 --- a/core/src/raw/oio/buf/chunked_bytes.rs +++ b/core/src/raw/oio/buf/chunked_bytes.rs @@ -328,13 +328,6 @@ impl oio::Stream for ChunkedBytes { None => Poll::Ready(None), } } - - fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Err(Error::new( - ErrorKind::Unsupported, - "ChunkedBytes does not support reset", - ))) - } } impl Stream for ChunkedBytes { diff --git a/core/src/raw/oio/cursor.rs b/core/src/raw/oio/cursor.rs index 0cc4e42a5df..a4b7caee373 100644 --- a/core/src/raw/oio/cursor.rs +++ b/core/src/raw/oio/cursor.rs @@ -166,9 +166,4 @@ impl oio::Stream for Cursor { self.pos += bs.len() as u64; Poll::Ready(Some(Ok(bs))) } - - fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll> { - self.pos = 0; - Poll::Ready(Ok(())) - } } diff --git a/core/src/raw/oio/stream/api.rs b/core/src/raw/oio/stream/api.rs index 9edfceb6a87..6dcbbb5a565 100644 --- a/core/src/raw/oio/stream/api.rs +++ b/core/src/raw/oio/stream/api.rs @@ -17,7 +17,6 @@ use std::future::Future; use std::pin::Pin; -use std::sync::Arc; use std::task::ready; use std::task::Context; use std::task::Poll; @@ -38,9 +37,6 @@ pub type Streamer = Box; pub trait Stream: Unpin + Send + Sync { /// Poll next item `Result` from the stream. fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll>>; - - /// Reset this stream to the beginning. - fn poll_reset(&mut self, cx: &mut Context<'_>) -> Poll>; } impl Stream for () { @@ -49,12 +45,6 @@ impl Stream for () { unimplemented!("poll_next is required to be implemented for oio::Stream") } - - fn poll_reset(&mut self, cx: &mut Context<'_>) -> Poll> { - let _ = cx; - - unimplemented!("poll_reset is required to be implemented for oio::Stream") - } } /// `Box` won't implement `Stream` automatically. @@ -63,66 +53,12 @@ impl Stream for Box { fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll>> { (**self).poll_next(cx) } - - fn poll_reset(&mut self, cx: &mut Context<'_>) -> Poll> { - (**self).poll_reset(cx) - } } impl Stream for dyn raw::oio::Read { fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll>> { raw::oio::Read::poll_next(self, cx) } - - fn poll_reset(&mut self, cx: &mut Context<'_>) -> Poll> { - let _ = raw::oio::Read::poll_seek(self, cx, std::io::SeekFrom::Start(0))?; - - Poll::Ready(Ok(())) - } -} - -impl Stream for Arc> { - fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll>> { - match self.try_lock() { - Ok(mut this) => this.poll_next(cx), - Err(_) => Poll::Ready(Some(Err(Error::new( - ErrorKind::Unexpected, - "the stream is expected to have only one consumer, but it's not", - )))), - } - } - - fn poll_reset(&mut self, cx: &mut Context<'_>) -> Poll> { - match self.try_lock() { - Ok(mut this) => this.poll_reset(cx), - Err(_) => Poll::Ready(Err(Error::new( - ErrorKind::Unexpected, - "the stream is expected to have only one consumer, but it's not", - ))), - } - } -} - -impl Stream for Arc> { - fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll>> { - match self.try_lock() { - Ok(mut this) => this.poll_next(cx), - Err(_) => Poll::Ready(Some(Err(Error::new( - ErrorKind::Unexpected, - "the stream is expected to have only one consumer, but it's not", - )))), - } - } - - fn poll_reset(&mut self, cx: &mut Context<'_>) -> Poll> { - match self.try_lock() { - Ok(mut this) => this.poll_reset(cx), - Err(_) => Poll::Ready(Err(Error::new( - ErrorKind::Unexpected, - "the stream is expected to have only one consumer, but it's not", - ))), - } - } } impl futures::Stream for dyn Stream { @@ -145,11 +81,6 @@ pub trait StreamExt: Stream { NextFuture { inner: self } } - /// Build a future for `poll_reset`. - fn reset(&mut self) -> ResetFuture<'_, Self> { - ResetFuture { inner: self } - } - /// Chain this stream with another stream. fn chain(self, other: S) -> Chain where @@ -192,24 +123,6 @@ where } } -/// Make this future `!Unpin` for compatibility with async trait methods. -#[pin_project(!Unpin)] -pub struct ResetFuture<'a, T: Stream + Unpin + ?Sized> { - inner: &'a mut T, -} - -impl Future for ResetFuture<'_, T> -where - T: Stream + Unpin + ?Sized, -{ - type Output = Result<()>; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - let this = self.project(); - Pin::new(this.inner).poll_reset(cx) - } -} - /// Stream for the [`chain`](StreamExt::chain) method. #[must_use = "streams do nothing unless polled"] pub struct Chain { @@ -228,13 +141,6 @@ impl Stream for Chain { } self.second.poll_next(cx) } - - fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Err(Error::new( - ErrorKind::Unsupported, - "chained stream doesn't support reset", - ))) - } } /// Stream for the [`collect`](StreamExt::collect) method. diff --git a/core/src/raw/oio/stream/into_stream.rs b/core/src/raw/oio/stream/into_stream.rs index fd01f3fccf2..2b21974378e 100644 --- a/core/src/raw/oio/stream/into_stream.rs +++ b/core/src/raw/oio/stream/into_stream.rs @@ -43,11 +43,4 @@ where fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll>> { self.inner.try_poll_next_unpin(cx) } - - fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Err(Error::new( - ErrorKind::Unsupported, - "IntoStream doesn't support reset", - ))) - } } diff --git a/core/src/raw/oio/stream/into_stream_from_reader.rs b/core/src/raw/oio/stream/into_stream_from_reader.rs index d8b29bff07b..cead7d11d72 100644 --- a/core/src/raw/oio/stream/into_stream_from_reader.rs +++ b/core/src/raw/oio/stream/into_stream_from_reader.rs @@ -89,11 +89,4 @@ where .set_source(err)))), } } - - fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Err(Error::new( - ErrorKind::Unsupported, - "FromReaderStream doesn't support reset", - ))) - } }