pub struct File<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize>where
D: BlockDevice,
T: TimeSource,{ /* private fields */ }
Expand description
A handle for an open file on disk, which closes on drop.
In contrast to a RawFile
, a File
holds a mutable reference to its
parent VolumeManager
, which restricts which operations you can perform.
If you drop a value of this type, it closes the file automatically, and but
error that may occur will be ignored. To handle potential errors, use
the File::close
method.
Implementations§
Source§impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
Sourcepub fn new(
raw_file: RawFile,
volume_mgr: &'a mut VolumeManager<D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>,
) -> File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
pub fn new( raw_file: RawFile, volume_mgr: &'a mut VolumeManager<D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>, ) -> File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
Create a new File
from a RawFile
Sourcepub fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error<D::Error>>
pub fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error<D::Error>>
Read from the file
Returns how many bytes were read, or an error.
Sourcepub fn seek_from_current(&mut self, offset: i32) -> Result<(), Error<D::Error>>
pub fn seek_from_current(&mut self, offset: i32) -> Result<(), Error<D::Error>>
Seek a file with an offset from the current position.
Sourcepub fn seek_from_start(&mut self, offset: u32) -> Result<(), Error<D::Error>>
pub fn seek_from_start(&mut self, offset: u32) -> Result<(), Error<D::Error>>
Seek a file with an offset from the start of the file.
Sourcepub fn seek_from_end(&mut self, offset: u32) -> Result<(), Error<D::Error>>
pub fn seek_from_end(&mut self, offset: u32) -> Result<(), Error<D::Error>>
Seek a file with an offset back from the end of the file.
Sourcepub fn to_raw_file(self) -> RawFile
pub fn to_raw_file(self) -> RawFile
Convert back to a raw file
Sourcepub fn flush(&mut self) -> Result<(), Error<D::Error>>
pub fn flush(&mut self) -> Result<(), Error<D::Error>>
Flush any written data by updating the directory entry.
Sourcepub fn close(self) -> Result<(), Error<D::Error>>
pub fn close(self) -> Result<(), Error<D::Error>>
Consume the File
handle and close it. The behavior of this is similar
to using core::mem::drop
or letting the File
go out of scope,
except this lets the user handle any errors that may occur in the process,
whereas when using drop, any errors will be discarded silently.