|
|
@ -4,7 +4,8 @@ use async_stream::stream; |
|
|
|
use futures_core::Stream; |
|
|
|
use futures_core::Stream; |
|
|
|
use futures_util::{StreamExt, pin_mut}; |
|
|
|
use futures_util::{StreamExt, pin_mut}; |
|
|
|
|
|
|
|
|
|
|
|
fn filenames(start: &Path) -> impl Stream<Item = PathBuf> + '_ { |
|
|
|
#[async_recursion::async_recursion] |
|
|
|
|
|
|
|
async fn filenames(start: &Path) -> impl Stream<Item = PathBuf> + '_ { |
|
|
|
stream! { |
|
|
|
stream! { |
|
|
|
let contents = tokio::fs::read_dir(start).await; |
|
|
|
let contents = tokio::fs::read_dir(start).await; |
|
|
|
if let Ok(mut reader) = contents { |
|
|
|
if let Ok(mut reader) = contents { |
|
|
@ -12,6 +13,35 @@ fn filenames(start: &Path) -> impl Stream<Item = PathBuf> + '_ { |
|
|
|
let entry = entry.path(); |
|
|
|
let entry = entry.path(); |
|
|
|
if entry.is_file() { |
|
|
|
if entry.is_file() { |
|
|
|
yield entry; |
|
|
|
yield entry; |
|
|
|
|
|
|
|
} else if entry.is_dir() { |
|
|
|
|
|
|
|
// And this doesn't work 'cause we can't yield its results and we can't return
|
|
|
|
|
|
|
|
// it due the return types being different.
|
|
|
|
|
|
|
|
let under_dir = filenames(&entry).await; |
|
|
|
|
|
|
|
pin_mut!(under_dir); |
|
|
|
|
|
|
|
while let Some(name) = under_dir.next().await { |
|
|
|
|
|
|
|
yield name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn sync_filenames(start: &Path) -> impl Stream<Item = PathBuf> + '_ { |
|
|
|
|
|
|
|
stream! { |
|
|
|
|
|
|
|
let contents = start.read_dir(); |
|
|
|
|
|
|
|
if let Ok(reader) = contents { |
|
|
|
|
|
|
|
for entry in reader { |
|
|
|
|
|
|
|
let entry = entry.unwrap().path(); |
|
|
|
|
|
|
|
if entry.is_file() { |
|
|
|
|
|
|
|
yield entry; |
|
|
|
|
|
|
|
} else if entry.is_dir() { |
|
|
|
|
|
|
|
let under_dir = sync_filenames(&entry); |
|
|
|
|
|
|
|
pin_mut!(under_dir); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while let Some(name) = under_dir.next().await { |
|
|
|
|
|
|
|
yield name |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -20,7 +50,9 @@ fn filenames(start: &Path) -> impl Stream<Item = PathBuf> + '_ { |
|
|
|
|
|
|
|
|
|
|
|
#[tokio::main(flavor = "current_thread")] |
|
|
|
#[tokio::main(flavor = "current_thread")] |
|
|
|
async fn main() { |
|
|
|
async fn main() { |
|
|
|
let name_stream = filenames(Path::new("src")); |
|
|
|
// let name_stream = filenames(Path::new(".")).await;
|
|
|
|
|
|
|
|
// pin_mut!(name_stream);
|
|
|
|
|
|
|
|
let name_stream = sync_filenames(Path::new(".")); |
|
|
|
pin_mut!(name_stream); |
|
|
|
pin_mut!(name_stream); |
|
|
|
|
|
|
|
|
|
|
|
while let Some(name) = name_stream.next().await { |
|
|
|
while let Some(name) = name_stream.next().await { |
|
|
|