Struct File

Source
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,

Source

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

Source

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.

Source

pub fn write(&mut self, buffer: &[u8]) -> Result<(), Error<D::Error>>

Write to the file

Source

pub fn is_eof(&self) -> bool

Check if a file is at End Of File.

Source

pub fn seek_from_current(&mut self, offset: i32) -> Result<(), Error<D::Error>>

Seek a file with an offset from the current position.

Source

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.

Source

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.

Source

pub fn length(&self) -> u32

Get the length of a file

Source

pub fn offset(&self) -> u32

Get the current offset of a file

Source

pub fn to_raw_file(self) -> RawFile

Convert back to a raw file

Source

pub fn flush(&mut self) -> Result<(), Error<D::Error>>

Flush any written data by updating the directory entry.

Source

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,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Freeze for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>

§

impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> RefUnwindSafe for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>

§

impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Send for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
where D: Send, T: Send,

§

impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Sync for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
where D: Sync, T: Sync,

§

impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Unpin for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>

§

impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> !UnwindSafe for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.