positioned_io/
refs.rs

1use std::{cell::RefCell, io};
2
3use super::{ReadAt, Size, WriteAt};
4
5impl<'a, R: ReadAt + ?Sized> ReadAt for &'a R {
6    fn read_at(&self, pos: u64, buf: &mut [u8]) -> io::Result<usize> {
7        R::read_at(self, pos, buf)
8    }
9}
10
11impl<'a, R: ReadAt + ?Sized> ReadAt for &'a mut R {
12    fn read_at(&self, pos: u64, buf: &mut [u8]) -> io::Result<usize> {
13        R::read_at(self, pos, buf)
14    }
15}
16
17impl<'a, W: WriteAt + ?Sized> WriteAt for &'a mut W {
18    fn write_at(&mut self, pos: u64, buf: &[u8]) -> io::Result<usize> {
19        W::write_at(self, pos, buf)
20    }
21
22    fn flush(&mut self) -> io::Result<()> {
23        W::flush(self)
24    }
25}
26
27impl<'a, S: Size + ?Sized> Size for &'a S {
28    fn size(&self) -> io::Result<Option<u64>> {
29        S::size(self)
30    }
31}
32impl<'a, S: Size + ?Sized> Size for &'a mut S {
33    fn size(&self) -> io::Result<Option<u64>> {
34        S::size(self)
35    }
36}
37
38impl<'a, R: ReadAt> ReadAt for &'a RefCell<R> {
39    fn read_at(&self, pos: u64, buf: &mut [u8]) -> io::Result<usize> {
40        self.borrow().read_at(pos, buf)
41    }
42}
43
44impl<'a, W: WriteAt> WriteAt for &'a RefCell<W> {
45    fn write_at(&mut self, pos: u64, buf: &[u8]) -> io::Result<usize> {
46        self.borrow_mut().write_at(pos, buf)
47    }
48
49    fn flush(&mut self) -> io::Result<()> {
50        self.borrow_mut().flush()
51    }
52}
53
54impl<'a, S: Size> Size for &'a RefCell<S> {
55    fn size(&self) -> io::Result<Option<u64>> {
56        self.borrow().size()
57    }
58}
59
60impl<R: ReadAt + ?Sized> ReadAt for Box<R> {
61    fn read_at(&self, pos: u64, buf: &mut [u8]) -> io::Result<usize> {
62        (**self).read_at(pos, buf)
63    }
64}
65
66impl<R: WriteAt + ?Sized> WriteAt for Box<R> {
67    fn write_at(&mut self, pos: u64, buf: &[u8]) -> io::Result<usize> {
68        (**self).write_at(pos, buf)
69    }
70
71    fn flush(&mut self) -> io::Result<()> {
72        (**self).flush()
73    }
74}
75
76impl<S: Size + ?Sized> Size for Box<S> {
77    fn size(&self) -> io::Result<Option<u64>> {
78        (**self).size()
79    }
80}