Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward default NamedTempFile methods #226

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,58 @@ impl<F: Read> Read for NamedTempFile<F> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.as_file_mut().read(buf).with_err_path(|| self.path())
}

fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
self.as_file_mut()
.read_vectored(bufs)
.with_err_path(|| self.path())
}

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
self.as_file_mut()
.read_to_end(buf)
.with_err_path(|| self.path())
}

fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
self.as_file_mut()
.read_to_string(buf)
.with_err_path(|| self.path())
}

fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
self.as_file_mut()
.read_exact(buf)
.with_err_path(|| self.path())
}
}

impl Read for &NamedTempFile<File> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.as_file().read(buf).with_err_path(|| self.path())
}

fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
self.as_file()
.read_vectored(bufs)
.with_err_path(|| self.path())
}

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
self.as_file()
.read_to_end(buf)
.with_err_path(|| self.path())
}

fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
self.as_file()
.read_to_string(buf)
.with_err_path(|| self.path())
}

fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
self.as_file().read_exact(buf).with_err_path(|| self.path())
}
}

impl<F: Write> Write for NamedTempFile<F> {
Expand All @@ -932,6 +978,24 @@ impl<F: Write> Write for NamedTempFile<F> {
fn flush(&mut self) -> io::Result<()> {
self.as_file_mut().flush().with_err_path(|| self.path())
}

fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
self.as_file_mut()
.write_vectored(bufs)
.with_err_path(|| self.path())
}

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.as_file_mut()
.write_all(buf)
.with_err_path(|| self.path())
}

fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
self.as_file_mut()
.write_fmt(fmt)
.with_err_path(|| self.path())
}
}

impl Write for &NamedTempFile<File> {
Expand All @@ -942,6 +1006,20 @@ impl Write for &NamedTempFile<File> {
fn flush(&mut self) -> io::Result<()> {
self.as_file().flush().with_err_path(|| self.path())
}

fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
self.as_file()
.write_vectored(bufs)
.with_err_path(|| self.path())
}

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.as_file().write_all(buf).with_err_path(|| self.path())
}

fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
self.as_file().write_fmt(fmt).with_err_path(|| self.path())
}
}

impl<F: Seek> Seek for NamedTempFile<F> {
Expand Down