使用 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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1216 次 |
| 最近记录: |