我可以创建一个单独的线程作为 I/O 队列,但我不确定这是否是最好的方法。它看起来是最好的。
我不知道如何使用 mio 加载本地文件.
最佳答案
使用 tokio::fs::read:
use tokio::prelude::Future;
fn main() {
let task = tokio::fs::read("/proc/cpuinfo").map(|data| {
// do something with the contents of the file ...
println!("contains {} bytes", data.len());
println!("{:?}", String::from_utf8(data));
}).map_err(|e| {
// handle errors
eprintln!("IO error: {:?}", e);
});
tokio::run(task);
}
关于rust - 如何异步读取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34360699/