pub struct File(/* private fields */);
Expand description
Represents an open File
Implementations§
Source§impl File
impl File
Sourcepub fn open(path: Path<'_>, flags: Flags) -> Result<Self>
pub fn open(path: Path<'_>, flags: Flags) -> Result<Self>
Open a file, given a path as UTF-8 string.
If the file does not exist, or is already open, it returns an error.
Path may be relative to current directory, or it may be an absolute path.
§Limitations
- You cannot open a file if it is currently open.
- Paths must confirm to the rules for the filesystem for the given drive.
- Relative paths are taken relative to the current directory (see
Api::chdir
).
Sourcepub fn write(&self, buffer: &[u8]) -> Result<()>
pub fn write(&self, buffer: &[u8]) -> Result<()>
Write to an open file handle, blocking until everything is written.
Some files do not support writing and will produce an error. You will also get an error if you run out of disk space.
The buffer
is only borrowed for the duration of the function call and
is then forgotten.
Sourcepub fn read(&self, buffer: &mut [u8]) -> Result<usize>
pub fn read(&self, buffer: &mut [u8]) -> Result<usize>
Read from an open file, returning how much was actually read.
You might get less data than you asked for. If you do an Api::read
and
you are already at the end of the file you will get
Err(Error::EndOfFile)
.
Data is stored to the given buffer. The
buffer` is only borrowed for
the duration of the function call and is then forgotten.
Sourcepub fn seek_set(&self, position: u64) -> Result<()>
pub fn seek_set(&self, position: u64) -> Result<()>
Move the file offset (for the given file handle) to the given position.
Some files do not support seeking and will produce an error.
Sourcepub fn seek_cur(&self, offset: i64) -> Result<u64>
pub fn seek_cur(&self, offset: i64) -> Result<u64>
Move the file offset (for the given file handle) relative to the current position.
Returns the new position, or an error.
Some files do not support seeking and will produce an error.
Sourcepub fn seek_end(&self) -> Result<u64>
pub fn seek_end(&self) -> Result<u64>
Move the file offset (for the given file handle) to the end of the file
Returns the new position, or an error.
Some files do not support seeking and will produce an error.
Sourcepub fn rename(old_path: Path<'_>, new_path: Path<'_>) -> Result<()>
pub fn rename(old_path: Path<'_>, new_path: Path<'_>) -> Result<()>
Rename a file.
§Limitations
- You cannot rename a file if it is currently open.
- You cannot rename a file where the
old_path
and thenew_path
are not on the same drive. - Paths must confirm to the rules for the filesystem for the given drive.