#reading #path #string #read #convenience #older #1-liner

unmaintained file

For Rust 1.25 and older. 1-liner convenience functions for reading and writing files

1 stable release

Uses old Rust 2015

1.1.2 May 9, 2018
1.1.1 Mar 29, 2017
1.0.0 Jul 17, 2016
0.1.0 Jul 14, 2016

#8 in #older

Download history 86/week @ 2023-11-26 102/week @ 2023-12-03 73/week @ 2023-12-10 74/week @ 2023-12-17 41/week @ 2023-12-24 16/week @ 2023-12-31 66/week @ 2024-01-07 69/week @ 2024-01-14 62/week @ 2024-01-21 65/week @ 2024-01-28 90/week @ 2024-02-04 100/week @ 2024-02-11 146/week @ 2024-02-18 97/week @ 2024-02-25 93/week @ 2024-03-03 41/week @ 2024-03-10

392 downloads per month
Used in 8 crates (7 directly)

MIT license

6KB
60 lines

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(())
}

No runtime deps