Skip to main content

File

Struct File 

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

an open file (closed when dropped): an OS file, or a stream of a vfs mount

Implementations§

Source§

impl File

Source

pub fn open(path: &str, mode: u32) -> Option<File>

FO_READ (existing, read only), FO_WRITE (create / truncate), FO_RW (open or create); on every mount (vfs.rs)

Source

pub fn create_new(path: &str) -> Option<File>

Create a named file exclusively; never open an existing path (a mount without OS files: exclusive inside this process).

Source

pub fn open_temp(dir: Option<&str>) -> Option<File>

a new file without a lasting name in dir (None = temp_dir) that disappears when it is closed (also after a crash); a mount without OS files: a file in memory [plat_file_open_temp]

Source

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

bytes read at off (fewer at the end of the file), None on an error before any byte

Source

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

bytes written at off (the file grows as needed), None on an error before any byte

Source

pub fn size(&self) -> Option<u64>

Source

pub fn sync(&self) -> bool

write cached data to the disk (a mount: where its readers find it)

Source

pub fn set_len(&self, len: u64) -> bool

cut or extend the file to len bytes

Trait Implementations§

Source§

impl Stream for File

Source§

fn read_at(&self, off: u64, buf: &mut [u8]) -> Option<usize>

bytes read at off (fewer at the end), None on an error
Source§

fn write_at(&self, off: u64, buf: &[u8]) -> Option<usize>

bytes written at off (the file grows); None for a read-only stream
Source§

fn size(&self) -> Option<u64>

Source§

fn set_len(&self, len: u64) -> bool

cut or extend to len bytes
Source§

fn sync(&self) -> bool

the data is where readers of the mount find it

Auto Trait Implementations§

§

impl !RefUnwindSafe for File

§

impl !UnwindSafe for File

§

impl Forget for File

§

impl Freeze for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnsafeUnpin 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.