io
io
I/O builtin namespace.
Runtime support: native runtimes.
Import
use io;
Functions
| Function | Description |
|---|---|
open | Opens a file handle as an io.file resource, or returns the OS error text. |
popen | Starts a child process and returns a process-backed io.file resource, or the OS error text. |
read_all | Reads all remaining text from an I/O handle, or returns the OS error text. |
read_line | Reads a single line from an I/O handle. End of file is Result::Ok(None); a present but empty line is Result::Ok(Some("")). |
write | Writes text to an I/O handle and returns the number of bytes written, or the OS error text. |
flush | Flushes buffered output for an I/O handle, or returns the OS error text. |
close | Closes an I/O handle, consuming the resource, or returns the OS error text. A close failure is reported instead of being swallowed. |
exists | Returns whether a file system path exists. |
Function details
open
fn open(path: string, mode: string) -> Result<io.file, string>
Opens a file handle as an io.file resource, or returns the OS error text.
popen
fn popen(command: string, mode: string) -> Result<io.file, string>
Starts a child process and returns a process-backed io.file resource, or the OS error text.
read_all
fn read_all(handle: io.file) -> Result<string, string>
Reads all remaining text from an I/O handle, or returns the OS error text.
read_line
fn read_line(handle: io.file) -> Result<Option<string>, string>
Reads a single line from an I/O handle. End of file is Result::Ok(None); a present but empty line is Result::Ok(Some("")).
write
fn write(handle: io.file, text: string) -> Result<int, string>
Writes text to an I/O handle and returns the number of bytes written, or the OS error text.
flush
fn flush(handle: io.file) -> Result<(), string>
Flushes buffered output for an I/O handle, or returns the OS error text.
close
fn close(handle: io.file) -> Result<(), string>
Closes an I/O handle, consuming the resource, or returns the OS error text. A close failure is reported instead of being swallowed.
exists
fn exists(path: string) -> bool
Returns whether a file system path exists.