Skip to main content

File

Struct File 

Source
pub struct File { /* private fields */ }
Expand description

A handle to an open file.

This is a wrapper around an osal_id_t that will automatically call OS_close when it goes out of scope, preventing resource leaks.

Implementations§

Source§

impl File

Source

pub fn id(&self) -> OsalId

Returns the underlying OSAL file ID.

Source

pub fn open(path: &str, access: AccessMode) -> Result<Self>

Opens a file with the specified access mode.

§Arguments
  • path: The virtual path to the file (e.g., “/ram/my_file.txt”).
  • access: The access mode, e.g., ffi::OS_READ_ONLY, ffi::OS_WRITE_ONLY, or ffi::OS_READ_WRITE.
Source

pub fn create(path: &str) -> Result<Self>

Creates a new file, or truncates an existing one, with read/write access.

§Arguments
  • path: The virtual path to the file to create (e.g., “/ram/new_file.dat”).
Source

pub fn sync_read(&mut self, buf: &mut [u8]) -> Result<usize>

Reads some bytes from the file into the specified buffer.

Returns the number of bytes read.

Source

pub fn sync_write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer to the file.

Returns the number of bytes written.

Source

pub fn seek(&mut self, pos: SeekFrom) -> Result<u32>

Seeks to an offset, in bytes, in a stream.

Returns the new position from the start of the file.

Source

pub fn read_header(&mut self) -> Result<FsHeader>

Reads the standard cFE File Header from the file.

Source

pub fn write_header(&mut self, hdr: &mut FsHeader) -> Result<()>

Writes the standard cFE File Header to the file.

Source

pub fn set_timestamp(&mut self, time: SysTime) -> Result<()>

Modifies the timestamp field in the cFE File Header.

Source

pub fn info(&self) -> Result<FileProp>

Retrieves information about this open file.

Source

pub fn timed_read(&mut self, buf: &mut [u8], timeout_ms: i32) -> Result<usize>

Reads from the file with a relative timeout.

Source

pub fn timed_read_abs( &mut self, buf: &mut [u8], abstime: OsTime, ) -> Result<usize>

Reads from the file with an absolute timeout.

Source

pub fn timed_write(&mut self, buf: &[u8], timeout_ms: i32) -> Result<usize>

Writes to the file with a relative timeout.

Source

pub fn timed_write_abs(&mut self, buf: &[u8], abstime: OsTime) -> Result<usize>

Writes to the file with an absolute timeout.

Source§

impl File

Source

pub fn read<'a>( &'a mut self, buf: &'a mut [u8], ) -> impl Future<Output = Result<usize>> + 'a

Asynchronously reads from the file into the provided buffer.

Source

pub fn write<'a>( &'a mut self, buf: &'a [u8], ) -> impl Future<Output = Result<usize>> + 'a

Asynchronously writes the provided buffer to the file.

Trait Implementations§

Source§

impl Debug for File

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for File

Source§

fn drop(&mut self)

Closes the file when the File object goes out of scope.

Auto Trait Implementations§

§

impl Freeze for File

§

impl RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnsafeUnpin for File

§

impl UnwindSafe for File

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.