Crate file [] [src]

File I/O 1-liners

file::get() and file::put() — read and write Vec<u8> with one function call.

extern crate file;

fn example() -> file::Result<()> {
    let data = file::get("some_input_file.dat")?;
    file::put("a.out", &data)?;
    Ok(())
}

file::Result is an alias for std::io::Result. You can use Result<(), Box<std::error::Error>> in places where you don't want to expose the error type.

Text file 1-liners

file::get_text() and file::put_text() — read and write String with one function call.

extern crate file;

fn example() -> file::Result<()> {
    let string = file::get_text("hello.txt")?;
    file::put("bye.txt", &string)?;
    Ok(())
}

Functions

get

Read a file into Vec<u8> from the given path. The path can be a string or a Path.

get_text

Read an UTF-8 encoded file into String from the given path. The path can be a string or a Path.

put

Creates a file at the given path with contents of Vec<u8> or &[u8], etc. Overwrites, non-atomically, if the file exists. The path can be a string or a Path.

put_text

Creates a file at the given path with given text contents, encoded as UTF-8. Overwrites, non-atomically, if the file exists. The path can be a string or a Path.

Type Definitions

Result

A specialized Result type for I/O operations.