3 个稳定版本
1.0.2 | 2022 年 5 月 11 日 |
---|
#1645 in Rust 模式
在 fold-license 中使用
7KB
59 行
write-to-file
将数据写入文件,简单的辅助函数和特质库 crate。
我厌倦了实现这些非常简单的文件写入功能,但我不需要更多的丰富功能。所以我发布了这个 crate。在轻松的氛围中享受 Rust。🤗
测试用例:tests/
函数版本使用
use write_to_file::write_to_file;
// write binary
let buf = vec![1u8, 2, 3, 4];
let path = "target/test/file.bin";
write_to_file(path, buf).unwrap(); // <- Easy to write!
// write text
let buf = "Nyanko is one of the greatest life.".to_string();
let path = "target/test/file.txt";
write_to_file(path, buf).unwrap(); // <- Easy to write!
特质版本使用
use write_to_file::WriteToFile;
// Vec<u8>
let buf: Vec<u8> = vec![1u8, 2, 3, 4];
let path = "target/test/file.bin";
buf.write_to_file(path).unwrap(); // <- Easy to write!
// &[u8]
let buf: &[u8] = buf.as_slice();
let path = "target/test/file.bin";
buf.write_to_file(path).unwrap(); // <- Easy to write!
// String
let buf: String = "Nyanko is one of the greatest life.".to_string();
let path = "target/test/file.txt";
buf.write_to_file(path).unwrap(); // <- Easy to write!
// &str
let buf: &str = buf.as_str();
let path = "target/test/file.txt";
buf.write_to_file(path).unwrap(); // <- Easy to write!
许可证
作者
- USAGI.NETWORK / Usagi Ito https://github.com/usagi/