Skip to content

Instantly share code, notes, and snippets.

@dhilst
Last active March 29, 2020 17:32
Show Gist options
  • Save dhilst/b851ca5b3f3d1e4e9fe93dde12db1e19 to your computer and use it in GitHub Desktop.
Save dhilst/b851ca5b3f3d1e4e9fe93dde12db1e19 to your computer and use it in GitHub Desktop.
#![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