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
use super::*;
use std::future::Future;
use std::ops::{Deref, DerefMut};
pub struct Page<'a, N: PageNo, const SIZE: usize> {
pub buf: [u8; SIZE],
pub(super) num: N,
pub(super) pages: &'a Pages<N, SIZE>,
pub(super) _lock: page_lock::WriteGuard<'a, N>,
}
impl<'a, N: PageNo, const SIZE: usize> Page<'a, N, SIZE> {
pub fn write(self) -> impl Future<Output = Result<()>> + 'a {
self.pages.write(self.num, self.buf)
}
pub fn write_buf(self, buf: [u8; SIZE]) -> impl Future<Output = Result<()>> + 'a {
self.pages.write(self.num, buf)
}
}
impl<N: PageNo, const SIZE: usize> Deref for Page<'_, N, SIZE> {
type Target = [u8; SIZE];
fn deref(&self) -> &Self::Target {
&self.buf
}
}
impl<N: PageNo, const SIZE: usize> DerefMut for Page<'_, N, SIZE> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.buf
}
}
pub struct Reader<'a, N: PageNo, T> {
pub(super) data: T,
pub(super) _guard: page_lock::ReadGuard<'a, N>,
}
impl<N: PageNo, T> Reader<'_, N, T> {
pub fn into_inner(self) -> T {
self.data
}
}
impl<N: PageNo, T> Deref for Reader<'_, N, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.data
}
}