From ae3add9c81ff8c8da66678524f822cd0eaee0b49 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 18 Oct 2024 21:22:39 -0400 Subject: [PATCH] Fixed recursion using a BoxFuture. --- src/command/build/walk_fs.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/command/build/walk_fs.rs b/src/command/build/walk_fs.rs index 9795ca1..143e811 100644 --- a/src/command/build/walk_fs.rs +++ b/src/command/build/walk_fs.rs @@ -1,26 +1,31 @@ use std::ops::AsyncFn; use std::path::Path; +use futures::future::BoxFuture; +use futures::FutureExt; use tokio::fs::DirEntry; use crate::error::CustomError; -pub(crate) async fn walk_fs>( +pub(crate) fn walk_fs + std::marker::Send + 'static>( root: P, predicate: fn(&DirEntry) -> Result, -) -> Result, CustomError> { - let mut ret = Vec::new(); - let mut entries = tokio::fs::read_dir(root).await?; - while let Some(entry) = entries.next_entry().await? { - let file_type = entry.file_type().await?; - if file_type.is_dir() { - let child_entries = walk_fs(entry.path(), predicate).await?; - ret.extend(child_entries); +) -> BoxFuture<'static, Result, CustomError>> { + async move { + let mut ret = Vec::new(); + let mut entries = tokio::fs::read_dir(root).await?; + while let Some(entry) = entries.next_entry().await? { + let file_type = entry.file_type().await?; + if file_type.is_dir() { + let child_entries = walk_fs(entry.path(), predicate).await?; + ret.extend(child_entries); + } + if predicate(&entry)? { + ret.push(entry); + } } - if predicate(&entry)? { - ret.push(entry); - } - } - Ok(ret) + Ok(ret) + } + .boxed() }