file

Crates.iofile
lib.rsfile
version1.1.2
sourcesrc
created_at2016-07-14 21:31:49.952307
updated_at2018-05-09 15:02:33.954529
descriptionFor Rust 1.25 and older. 1-liner convenience functions for reading and writing files
homepage
repositoryhttps://github.com/kornelski/rust-file.git
max_upload_size
id5668
size5,843
Dylan DPC (Dylan-DPC)

documentation

https://kornelski.github.io/rust-file/file/

README

File I/O 1-liners for old Rust

This crate is obsolete since Rust 1.26. If you have a file-related Rust project and would like to use this crate name, let me know!

Vec<u8>

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

Use std::fs::read("path")? and std::fs::write("path", data)? in Rust 1.26 or later.

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.

String

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

Use std::fs::read_to_string("path")? and and std::fs::write("path", string)? in Rust 1.26 or later.

extern crate file;

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

cargo fmt