smol/examples/read-dir.rs

24 lines
503 B
Rust
Raw Normal View History

2020-04-21 15:51:07 +00:00
// TODO: document
2020-02-09 14:32:44 +00:00
//! Lists files in a directory given as an argument.
use std::env;
use std::fs;
use futures::io;
use futures::prelude::*;
2020-04-19 09:29:52 +00:00
use smol::blocking;
2020-02-09 14:32:44 +00:00
fn main() -> io::Result<()> {
let path = env::args().nth(1).expect("missing path argument");
smol::run(async move {
2020-04-19 09:29:52 +00:00
let mut dir = smol::iter(blocking!(fs::read_dir(path))?);
2020-02-09 14:32:44 +00:00
while let Some(res) = dir.next().await {
println!("{}", res?.file_name().to_string_lossy());
}
Ok(())
})
}