Struct File

Source
pub struct File(/* private fields */);
Expand description

Represents an open File

Implementations§

Source§

impl File

Source

pub fn open(path: Path<'_>, flags: Flags) -> Result<Self>

Open a file, given a path as UTF-8 string.

If the file does not exist, or is already open, it returns an error.

Path may be relative to current directory, or it may be an absolute path.

§Limitations
  • You cannot open a file if it is currently open.
  • Paths must confirm to the rules for the filesystem for the given drive.
  • Relative paths are taken relative to the current directory (see Api::chdir).
Source

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

Write to an open file handle, blocking until everything is written.

Some files do not support writing and will produce an error. You will also get an error if you run out of disk space.

The buffer is only borrowed for the duration of the function call and is then forgotten.

Source

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

Read from an open file, returning how much was actually read.

You might get less data than you asked for. If you do an Api::read and you are already at the end of the file you will get Err(Error::EndOfFile).

Data is stored to the given buffer. The buffer` is only borrowed for the duration of the function call and is then forgotten.

Source

pub fn close(self) -> Result<()>

Close a file

Source

pub fn seek_set(&self, position: u64) -> Result<()>

Move the file offset (for the given file handle) to the given position.

Some files do not support seeking and will produce an error.

Source

pub fn seek_cur(&self, offset: i64) -> Result<u64>

Move the file offset (for the given file handle) relative to the current position.

Returns the new position, or an error.

Some files do not support seeking and will produce an error.

Source

pub fn seek_end(&self) -> Result<u64>

Move the file offset (for the given file handle) to the end of the file

Returns the new position, or an error.

Some files do not support seeking and will produce an error.

Source

pub fn rename(old_path: Path<'_>, new_path: Path<'_>) -> Result<()>

Rename a file.

§Limitations
  • You cannot rename a file if it is currently open.
  • You cannot rename a file where the old_path and the new_path are not on the same drive.
  • Paths must confirm to the rules for the filesystem for the given drive.
Source

pub fn ioctl(&self, command: u64, value: u64) -> Result<u64>

Perform a special I/O control operation.

The allowed values of command and value are TBD.

Source

pub fn stat(&self) -> Result<Stat>

Get information about this file.

Trait Implementations§

Source§

impl Drop for File

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Write for &File

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

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

Glue for usage of the write! macro with implementors of this trait. Read more
Source§

impl Write for File

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

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

Glue for usage of the write! macro with implementors of this trait. 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>,

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.