Fixed recursion using a BoxFuture.
This commit is contained in:
parent
98fa43575d
commit
ae3add9c81
@ -1,14 +1,17 @@
|
|||||||
use std::ops::AsyncFn;
|
use std::ops::AsyncFn;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use futures::future::BoxFuture;
|
||||||
|
use futures::FutureExt;
|
||||||
use tokio::fs::DirEntry;
|
use tokio::fs::DirEntry;
|
||||||
|
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
|
||||||
pub(crate) async fn walk_fs<P: AsRef<Path>>(
|
pub(crate) fn walk_fs<P: AsRef<Path> + std::marker::Send + 'static>(
|
||||||
root: P,
|
root: P,
|
||||||
predicate: fn(&DirEntry) -> Result<bool, CustomError>,
|
predicate: fn(&DirEntry) -> Result<bool, CustomError>,
|
||||||
) -> Result<Vec<DirEntry>, CustomError> {
|
) -> BoxFuture<'static, Result<Vec<DirEntry>, CustomError>> {
|
||||||
|
async move {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
let mut entries = tokio::fs::read_dir(root).await?;
|
let mut entries = tokio::fs::read_dir(root).await?;
|
||||||
while let Some(entry) = entries.next_entry().await? {
|
while let Some(entry) = entries.next_entry().await? {
|
||||||
@ -24,3 +27,5 @@ pub(crate) async fn walk_fs<P: AsRef<Path>>(
|
|||||||
|
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
.boxed()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user