Struct axfs::fops::File

source ·
pub struct File { /* private fields */ }
Expand description

An opened file object, with open permissions and a cursor.

Implementations§

source§

impl File

source

pub fn open(path: &str, opts: &OpenOptions) -> AxResult<Self>

Opens a file at the path relative to the current directory. Returns a File object.

source

pub fn truncate(&self, size: u64) -> AxResult

Truncates the file to the specified size.

source

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

Reads the file at the current position. Returns the number of bytes read.

After the read, the cursor will be advanced by the number of bytes read.

source

pub fn read_at(&self, offset: u64, buf: &mut [u8]) -> AxResult<usize>

Reads the file at the given position. Returns the number of bytes read.

It does not update the file cursor.

source

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

Writes the file at the current position. Returns the number of bytes written.

After the write, the cursor will be advanced by the number of bytes written.

source

pub fn write_at(&self, offset: u64, buf: &[u8]) -> AxResult<usize>

Writes the file at the given position. Returns the number of bytes written.

It does not update the file cursor.

source

pub fn flush(&self) -> AxResult

Flushes the file, writes all buffered data to the underlying device.

source

pub fn seek(&mut self, pos: SeekFrom) -> AxResult<u64>

Sets the cursor of the file to the specified offset. Returns the new position after the seek.

source

pub fn get_attr(&self) -> AxResult<FileAttr>

Gets the file attributes.

Trait Implementations§

source§

impl Drop for File

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for File

§

impl !RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin 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>,

§

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

§

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.