1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
cfg_sync!(
mod sync_impl;
pub use sync_impl::{MmapFileReader, MmapFileReaderExt};
);
cfg_async! {
macro_rules! declare_and_impl_basic_reader {
() => {
pin_project! {
/// AsyncMmapFileReader helps read data from mmap file
/// like a normal file.
pub struct AsyncMmapFileReader<'a> {
#[pin]
r: Cursor<&'a [u8]>,
offset: usize,
len: usize,
}
}
impl<'a> AsyncMmapFileReader<'a> {
pub(crate) fn new(r: Cursor<&'a [u8]>, offset: usize, len: usize) -> Self {
Self {
r,
offset,
len
}
}
/// Returns the start offset(related to the mmap) of the reader
#[inline]
pub fn offset(&self) -> usize {
self.offset
}
/// Returns the length of the reader
#[inline]
pub fn len(&self) -> usize {
self.len
}
}
impl Debug for AsyncMmapFileReader<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AsyncMmapFileReader")
.field("offset", &self.offset)
.field("len", &self.len)
.field("reader", &self.r)
.finish()
}
}
};
}
}
cfg_async_std!(
pub(crate) mod async_std_impl;
);
cfg_smol!(
pub(crate) mod smol_impl;
);
cfg_tokio!(
pub(crate) mod tokio_impl;
);