Skip to main content

rustfs_rio/
reader.rs

1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::pin::Pin;
16use std::task::{Context, Poll};
17use tokio::io::{AsyncRead, ReadBuf};
18
19use crate::compress_index::TryGetIndex;
20use crate::{EtagResolvable, HashReaderDetector, Reader};
21
22pub struct WarpReader<R> {
23    inner: R,
24}
25
26impl<R: AsyncRead + Unpin + Send + Sync> WarpReader<R> {
27    pub fn new(inner: R) -> Self {
28        Self { inner }
29    }
30}
31
32impl<R: AsyncRead + Unpin + Send + Sync> AsyncRead for WarpReader<R> {
33    fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<std::io::Result<()>> {
34        Pin::new(&mut self.inner).poll_read(cx, buf)
35    }
36}
37
38impl<R: AsyncRead + Unpin + Send + Sync> HashReaderDetector for WarpReader<R> {}
39
40impl<R: AsyncRead + Unpin + Send + Sync> EtagResolvable for WarpReader<R> {}
41
42impl<R: AsyncRead + Unpin + Send + Sync> TryGetIndex for WarpReader<R> {}
43
44impl<R: AsyncRead + Unpin + Send + Sync> Reader for WarpReader<R> {}