1 个稳定版本
使用旧的 Rust 2015
| 1.1.2 | 2018 年 5 月 9 日 |
|---|---|
| 1.1.1 |
|
| 1.0.0 |
|
| 0.1.0 |
|
#8 in #older
392 每月下载量
用于 8 个软件包(7 个直接使用)
6KB
60 行
旧 Rust 的文件 I/O 单行函数
由于 Rust 1.26 已弃用此软件包。如果您有一个与文件相关的 Rust 项目并希望使用此软件包名称,请告诉我!
Vec<u8>
file::get() 和 file::put() — 在 Rust 1.26 之前,使用一个函数调用读取和写入 Vec<u8>。
在 Rust 1.26 或更高版本中使用 std::fs::read("path")? 和 std::fs::write("path", data)?。
extern crate file;
fn example() -> file::Result<()> {
let data = file::get("some_input_file.dat")?;
file::put("a.out", &data)?;
Ok(())
}
file::Result 是 std::io::Result 的别名。您可以在不希望暴露错误类型的地方使用 Result<(), Box<std::error::Error>>。
String
file::get_text() 和 file::put_text() —— 通过一次函数调用读取和写入 String。
在 Rust 1.26 或更高版本中,使用 std::fs::read_to_string("path")? 和 std::fs::write("path", string)?。
extern crate file;
fn example() -> file::Result<()> {
let string = file::get_text("hello.txt")?;
file::put_text("bye.txt", &string)?;
Ok(())
}