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
use std::cell::RefCell;
use std::io;

use super::{ReadAt, WriteAt, Size};

impl<'a, R: ReadAt + ?Sized> ReadAt for &'a R {
    fn read_at(&self, pos: u64, buf: &mut [u8]) -> io::Result<usize> {
        R::read_at(self, pos, buf)
    }
}

impl<'a, R: ReadAt + ?Sized> ReadAt for &'a mut R {
    fn read_at(&self, pos: u64, buf: &mut [u8]) -> io::Result<usize> {
        R::read_at(self, pos, buf)
    }
}

impl<'a, W: WriteAt + ?Sized> WriteAt for &'a mut W {
    fn write_at(&mut self, pos: u64, buf: &[u8]) -> io::Result<usize> {
        W::write_at(self, pos, buf)
    }

    fn flush(&mut self) -> io::Result<()> {
        W::flush(self)
    }
}

impl<'a, S: Size + ?Sized> Size for &'a S {
    fn size(&self) -> io::Result<Option<u64>> {
        S::size(self)
    }
}
impl<'a, S: Size + ?Sized> Size for &'a mut S {
    fn size(&self) -> io::Result<Option<u64>> {
        S::size(self)
    }
}

impl<'a, R: ReadAt> ReadAt for &'a RefCell<R> {
    fn read_at(&self, pos: u64, buf: &mut [u8]) -> io::Result<usize> {
        self.borrow().read_at(pos, buf)
    }
}

impl<'a, W: WriteAt> WriteAt for &'a RefCell<W> {
    fn write_at(&mut self, pos: u64, buf: &[u8]) -> io::Result<usize> {
        self.borrow_mut().write_at(pos, buf)
    }

    fn flush(&mut self) -> io::Result<()> {
        self.borrow_mut().flush()
    }
}

impl<'a, S: Size> Size for &'a RefCell<S> {
    fn size(&self) -> io::Result<Option<u64>> {
        self.borrow().size()
    }
}