Last active
March 29, 2020 17:32
-
-
Save dhilst/b851ca5b3f3d1e4e9fe93dde12db1e19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused_variables)] | |
use futures::future::LocalBoxFuture; | |
use futures::prelude::*; | |
use std::path::Path; | |
use tokio::fs::*; | |
fn walkdir<'a, C>(path: &'a Path, cb: &'a mut C) -> LocalBoxFuture<'a, ()> | |
where | |
C: Fn(&DirEntry), | |
{ | |
async move { | |
let mut dir = read_dir(path).await.unwrap(); | |
while let Some(dentry) = dir.next().await { | |
let dentry = dentry.unwrap(); | |
cb(&dentry); | |
if dentry.file_type().await.unwrap().is_dir() { | |
let dentry_path = dentry.path(); | |
walkdir(dentry_path.as_path(), cb).await; | |
} | |
} | |
} | |
.boxed_local() | |
} | |
#[tokio::main] | |
async fn main() { | |
walkdir(Path::new(".").as_ref(), &mut |d: &DirEntry| { | |
println!("{}", d.file_name().into_string().unwrap()); | |
}) | |
.await; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment