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 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 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(&self, buffer: &mut [u8]) -> Result<usize, Error<D::Error>>
pub fn read(&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(&self, offset: i32) -> Result<(), Error<D::Error>>
pub fn seek_from_current(&self, offset: i32) -> Result<(), Error<D::Error>>
Seek a file with an offset from the current position.
Sourcepub fn seek_from_start(&self, offset: u32) -> Result<(), Error<D::Error>>
pub fn seek_from_start(&self, offset: u32) -> Result<(), Error<D::Error>>
Seek a file with an offset from the start of the file.
Sourcepub fn seek_from_end(&self, offset: u32) -> Result<(), Error<D::Error>>
pub fn seek_from_end(&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(&self) -> Result<(), Error<D::Error>>
pub fn flush(&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.
Trait Implementations§
Source§impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Debug for 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> Debug for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
Source§impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Drop for 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> Drop for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
Source§impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> ErrorType for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> ErrorType for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
Source§impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Read for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Read for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf
. Read more