rustfs_rio/
lib.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
15mod limit_reader;
16
17pub use limit_reader::LimitReader;
18
19mod etag_reader;
20pub use etag_reader::EtagReader;
21
22mod compress_index;
23mod compress_reader;
24pub use compress_reader::{CompressReader, DecompressReader};
25
26mod encrypt_reader;
27pub use encrypt_reader::{DecryptReader, EncryptReader};
28
29mod hardlimit_reader;
30pub use hardlimit_reader::HardLimitReader;
31
32mod hash_reader;
33pub use hash_reader::*;
34
35pub mod reader;
36pub use reader::WarpReader;
37
38mod writer;
39pub use writer::*;
40
41mod http_reader;
42pub use http_reader::*;
43
44pub use compress_index::TryGetIndex;
45
46mod etag;
47
48pub trait Reader: tokio::io::AsyncRead + Unpin + Send + Sync + EtagResolvable + HashReaderDetector + TryGetIndex {}
49
50// Trait for types that can be recursively searched for etag capability
51pub trait EtagResolvable {
52    fn is_etag_reader(&self) -> bool {
53        false
54    }
55    fn try_resolve_etag(&mut self) -> Option<String> {
56        None
57    }
58}
59
60// Generic function that can work with any EtagResolvable type
61pub fn resolve_etag_generic<R>(reader: &mut R) -> Option<String>
62where
63    R: EtagResolvable,
64{
65    reader.try_resolve_etag()
66}
67
68/// Trait to detect and manipulate HashReader instances
69pub trait HashReaderDetector {
70    fn is_hash_reader(&self) -> bool {
71        false
72    }
73
74    fn as_hash_reader_mut(&mut self) -> Option<&mut dyn HashReaderMut> {
75        None
76    }
77}
78
79impl Reader for crate::HashReader {}
80impl Reader for crate::HardLimitReader {}
81impl Reader for crate::EtagReader {}
82impl<R> Reader for crate::CompressReader<R> where R: Reader {}
83impl<R> Reader for crate::EncryptReader<R> where R: Reader {}