Added io::{Read, Seek, Write} impl for opened drv files.

This commit is contained in:
Filipe Rodrigues 2021-05-22 23:48:24 +01:00
parent 69236ca742
commit a349a81d51
2 changed files with 25 additions and 1 deletions

View File

@ -275,3 +275,27 @@ pub struct OpenFile<'a, T> {
/// Inner
inner: IoCursor<T>,
}
impl<'a, T: io::Seek + io::Read> io::Read for OpenFile<'a, T> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.read(buf)
}
}
impl<'a, T: io::Seek> io::Seek for OpenFile<'a, T> {
fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> {
// TODO: Allow file to expand beyond here too.
self.inner.seek(pos)
}
}
impl<'a, T: io::Seek + io::Write> io::Write for OpenFile<'a, T> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
// TODO: Allow file to expand beyond
self.inner.write(buf)
}
fn flush(&mut self) -> io::Result<()> {
self.inner.flush()
}
}

View File

@ -66,7 +66,7 @@ impl<T: Write + Seek> Write for IoCursor<T> {
}
}
impl<T: Read + Seek> Seek for IoCursor<T> {
impl<T: Seek> Seek for IoCursor<T> {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
match pos {
SeekFrom::Start(pos) => {