File: ls.rs

package info (click to toggle)
rust-blocking 1.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 244 kB
  • sloc: makefile: 2; sh: 1
file content (26 lines) | stat: -rw-r--r-- 525 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//! Lists contents of a directory.
//!
//! Run with:
//!
//! ```
//! cargo run --example ls .
//! ```

use std::{env, fs, io};

use blocking::Unblock;
use futures_lite::{future, prelude::*};

fn main() -> io::Result<()> {
    let path = env::args().nth(1).unwrap_or_else(|| ".".into());

    future::block_on(async {
        let mut dir = Unblock::new(fs::read_dir(path)?);

        while let Some(item) = dir.next().await {
            println!("{}", item?.file_name().to_string_lossy());
        }

        Ok(())
    })
}