Skip to main content

File

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, but any 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 VolumeManager<D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>, ) -> Self

Create a new File from a RawFile

Source

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.

See VolumeManager::read for details, except the file given is this file.

Source

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

Write to the file

See VolumeManager::write for details, except the file given is this file.

Source

pub fn is_eof(&self) -> bool

Check if a file is at End Of File.

See VolumeManager::file_eof for details, except the file given is this file.

Source

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

Seek a file with an offset from the current position.

See VolumeManager::file_seek_from_current for details, except the file given is this file.

Source

pub fn seek_from_start(&self, offset: u32) -> Result<(), Error<D::Error>>

Seek a file with an offset from the start of the file.

See VolumeManager::file_seek_from_start for details, except the file given is this file.

Source

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.

See VolumeManager::file_seek_from_end for details, except the file given is this file.

Source

pub fn length(&self) -> u32

Get the length of a file

See VolumeManager::file_length for details, except the file given is this file.

Source

pub fn offset(&self) -> u32

Get the current offset of a file

See VolumeManager::file_offset for details, except the file given is this file.

Source

pub fn to_raw_file(self) -> RawFile

Convert back to a raw file

Source

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

Flush any written data by updating the directory entry.

See VolumeManager::flush_file for details, except the file given is this file.

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

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
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>

Source§

type Error = Error<<D as BlockDevice>::Error>

Error type of all the IO operations on this type.
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>

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
Source§

impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Seek for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>

Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>

Seek to an offset, in bytes, in a stream. A seek beyond the end of a stream is allowed, but behavior is defined by the implementation. Read more
Source§

fn rewind(&mut self) -> Result<(), Self::Error>

Rewind to the beginning of a stream. Read more
Source§

fn stream_position(&mut self) -> Result<u64, Self::Error>

Returns the current seek position from the start of the stream. Read more
Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error>

Seeks relative to the current position. Read more
Source§

impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Write for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
Source§

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

Flush this output stream, blocking until all intermediately buffered contents reach their destination.
Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more
Source§

fn write_fmt( &mut self, fmt: Arguments<'_>, ) -> Result<(), WriteFmtError<Self::Error>>

Write a formatted string into this writer, returning any error encountered. Read more

Auto Trait Implementations§

§

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>

§

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>

§

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>

§

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> 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> UnsafeUnpin 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.