Struct

std::io::File!

source
struct File! { ... }

Owns one open file descriptor. Read it through input, write it through output, or call close to consume it.

Methods

method open_readsource

forall C, S where ReadBytes[C, S], Copy[S].
fn open_read(&cx: C, path: S) -> Result[File!, Error] { ... }

Opens the file at path, any byte view read through cx, read-only. Safe: the descriptor it wraps is always one this call opened. Fails with the errno of open(2), or EINVAL for a path holding a NUL.

method createsource

forall C, S where ReadBytes[C, S], Copy[S].
fn create(&cx: C, path: S) -> Result[File!, Error] { ... }

Creates the file at path, or empties it, and opens it for writing; a new file gets mode 0644 less the umask. Fails as open_read does.

method adoptsource

unsafe fn adopt(fd: i32) -> File! { ... }

Wraps an already-open descriptor obtained elsewhere as an owning File!. Caller: fd is live and open with no other owner, and this File!'s close is the program's only remaining use of it -- the HeapAllocator::adopt_raw obligation, for descriptors.

method closesource

fn close(self) -> Result[(), Error] { ... }

Closes the descriptor.

The terminal operation: the checker requires every File! to reach close. The File! is consumed even when close(2) fails, which is reported with its errno.

method file_sizesource

fn file_size(&self) -> Result[u64, Error] { ... }

The byte size of a regular file, from fstat(2). Anything else is an error: EISDIR for a directory, EINVAL for a pipe, device or socket, whose size says nothing about what a read will return. A u64, as std::fs::Metadata's size is: a file's size is the file system's number, which a 32-bit address space need not hold.

method descriptorsource

fn descriptor(&self) -> i32 { ... }

The descriptor's number, for a C interface or another process (a std::process::Stdio!::File hands a child a copy). No safe function takes a number to read, write or close, so it grants nothing.

method inputsource

fn input(self) -> Input! { ... }

A reader of the file from its offset, which owns it and closes it on read_to_end or finish.

method outputsource

fn output(self) -> Output! { ... }

A buffered writer to the file at its offset, which owns it and closes it on finish.