Trait system_interface::fs::FileIoExt
source · pub trait FileIoExt: IoExt {
Show 16 methods
fn advise(&self, offset: u64, len: u64, advice: Advice) -> Result<()>;
fn allocate(&self, offset: u64, len: u64) -> Result<()>;
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>;
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>;
fn read_to_end_at(&self, buf: &mut Vec<u8>, offset: u64) -> Result<usize>;
fn read_to_string_at(&self, buf: &mut String, offset: u64) -> Result<usize>;
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>;
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>;
fn seek(&self, pos: SeekFrom) -> Result<u64>;
fn stream_position(&self) -> Result<u64>;
fn read_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<usize> { ... }
fn read_exact_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<()> { ... }
fn is_read_vectored_at(&self) -> bool { ... }
fn write_vectored_at(
&self,
bufs: &[IoSlice<'_>],
offset: u64
) -> Result<usize> { ... }
fn write_all_vectored_at(
&self,
bufs: &mut [IoSlice<'_>],
offset: u64
) -> Result<()> { ... }
fn is_write_vectored_at(&self) -> bool { ... }
}Expand description
Extension trait for std::fs::File and cap_std::fs::File.
Required Methods§
sourcefn advise(&self, offset: u64, len: u64, advice: Advice) -> Result<()>
fn advise(&self, offset: u64, len: u64, advice: Advice) -> Result<()>
Announce the expected access pattern of the data at the given offset.
sourcefn allocate(&self, offset: u64, len: u64) -> Result<()>
fn allocate(&self, offset: u64, len: u64) -> Result<()>
Allocate space in the file, increasing the file size as needed, and ensuring that there are no holes under the given range.
sourcefn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
Reads a number of bytes starting from a given offset.
This is similar to std::os::unix::fs::FileExt::read_at, except it
takes self by immutable reference since the entire side effect is
I/O, and it’s supported on non-Unix platforms including Windows.
sourcefn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
Reads the exact number of byte required to fill buf from the given offset.
This is similar to std::os::unix::fs::FileExt::read_exact_at,
except it takes self by immutable reference since the entire side
effect is I/O, and it’s supported on non-Unix platforms including
Windows.
sourcefn read_to_end_at(&self, buf: &mut Vec<u8>, offset: u64) -> Result<usize>
fn read_to_end_at(&self, buf: &mut Vec<u8>, offset: u64) -> Result<usize>
Read all bytes, starting at offset, until EOF in this source, placing
them into buf.
sourcefn read_to_string_at(&self, buf: &mut String, offset: u64) -> Result<usize>
fn read_to_string_at(&self, buf: &mut String, offset: u64) -> Result<usize>
Read all bytes, starting at offset, until EOF in this source,
appending them to buf.
sourcefn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>
Writes a number of bytes starting from a given offset.
This is similar to std::os::unix::fs::FileExt::write_at, except it
takes self by immutable reference since the entire side effect is
I/O, and it’s supported on non-Unix platforms including Windows.
sourcefn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>
Attempts to write an entire buffer starting from a given offset.
This is similar to std::os::unix::fs::FileExt::write_all_at, except
it takes self by immutable reference since the entire side effect is
I/O, and it’s supported on non-Unix platforms including Windows.
sourcefn seek(&self, pos: SeekFrom) -> Result<u64>
fn seek(&self, pos: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream.
This is similar to std::io::Seek::seek, except it takes self by
immutable reference since the entire side effect is I/O.
sourcefn stream_position(&self) -> Result<u64>
fn stream_position(&self) -> Result<u64>
Returns the current seek position from the start of the stream.
This is similar to std::io::Seek::stream_position, except it’s
available on Rust stable.
This may eventually be implemented by rust-lang/rust#62726.
Provided Methods§
sourcefn read_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<usize>
fn read_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<usize>
Is to read_vectored what read_at is to read.
Examples found in repository?
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
fn read_exact_vectored_at(
&self,
mut bufs: &mut [IoSliceMut],
mut offset: u64,
) -> io::Result<()> {
bufs = skip_leading_empties(bufs);
while !bufs.is_empty() {
match self.read_vectored_at(bufs, offset) {
Ok(0) => {
return Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"failed to fill whole buffer",
))
}
Ok(nread) => {
offset = offset
.checked_add(nread.try_into().unwrap())
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "offset overflow"))?;
bufs = advance_mut(bufs, nread);
}
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => (),
Err(e) => return Err(e),
}
bufs = skip_leading_empties(bufs);
}
Ok(())
}sourcefn read_exact_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<()>
fn read_exact_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<()>
Is to read_exact_vectored what read_exact_at is to read_exact.
sourcefn is_read_vectored_at(&self) -> bool
fn is_read_vectored_at(&self) -> bool
Determines if this Reader has an efficient read_vectored_at
implementation.
sourcefn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> Result<usize>
fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> Result<usize>
Is to write_vectored what write_at is to write.
Examples found in repository?
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
fn write_all_vectored_at(&self, mut bufs: &mut [IoSlice], mut offset: u64) -> io::Result<()> {
while !bufs.is_empty() {
match self.write_vectored_at(bufs, offset) {
Ok(nwritten) => {
offset = offset
.checked_add(nwritten.try_into().unwrap())
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "offset overflow"))?;
bufs = advance(bufs, nwritten);
}
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => (),
Err(e) => return Err(e),
}
}
Ok(())
}sourcefn write_all_vectored_at(
&self,
bufs: &mut [IoSlice<'_>],
offset: u64
) -> Result<()>
fn write_all_vectored_at(
&self,
bufs: &mut [IoSlice<'_>],
offset: u64
) -> Result<()>
Is to write_all_vectored what write_all_at is to write_all.
sourcefn is_write_vectored_at(&self) -> bool
fn is_write_vectored_at(&self) -> bool
Determines if this Writer has an efficient write_vectored_at
implementation.
Implementors§
impl<T: AsFilelike + IoExt> FileIoExt for T
Implement FileIoExt for any type which implements AsRawFd.