xur_

> module

std::fs

filesystem access

use std::fs; feature fs in the browser (in-memory)

std::fs reads and writes files. Functions that touch the filesystem return Result with the shared io::Error on failure. Relative paths are relative to the current directory.

> functions

# append(path: str, contents: str) -> Result<(), Error>

Adds a string to the end of a file, creating it if needed.

# create_dir_all(path: str) -> Result<(), Error>

Creates a directory and any missing parents. A directory that already exists is not an error.

# exists(path: str) -> bool

Whether a path exists.

# read(path: str) -> Result<bytes, Error>

Reads a whole file as raw bytes.

# read_dir(path: str) -> Result<list<str>, Error>

The names of the entries in a directory (not their full paths), sorted.

# read_to_string(path: str) -> Result<str, Error>

Reads a whole file as text. Err(io::Error::InvalidInput) if it isn't valid UTF-8.

# remove(path: str) -> Result<(), Error>

Deletes a file. It doesn't remove directories.

# write(path: str, contents: str) -> Result<(), Error>

Writes a string to a file, creating it or replacing its contents.

# write_bytes(path: str, data: bytes) -> Result<(), Error>

Writes raw bytes to a file, creating it or replacing its contents.

> types

┌ type File

A File is an open file. Copies of it share the same file and position.

An open file, shared by every Xur value referring to it.

# File::create(path: str) -> Result<File, Error>

Creates a file for writing, or empties an existing one.

# File::open(path: str) -> Result<File, Error>

Opens a file for reading.

# file.read_to_string() -> Result<str, Error>

Reads from the current position to the end, as text.

# file.write(contents: str) -> Result<(), Error>

Writes all of a string at the current position.

> errors

Fallible functions return the shared io::Error (see xur.std.io(7)), e.g. Err(io::Error::NotFound).

> examples

use std::fs;
use std::io;

fn main() -> Result<()> {
    fs::write("greeting.txt", "hello")?;
    let text = fs::read_to_string("greeting.txt")?;
    io::println("{}", text);
    Ok(())
}