From 7029eba2370ca05a8824541058ab9ea867037b03 Mon Sep 17 00:00:00 2001 From: Gwo Tzu-Hsing Date: Wed, 18 Dec 2024 17:54:24 +0800 Subject: [PATCH] feat: refactor implement `MaybeSend` for fs::list returning stream --- fusio/src/dynamic/fs.rs | 13 +++++++------ fusio/src/dynamic/mod.rs | 5 +++++ fusio/src/fs/mod.rs | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/fusio/src/dynamic/fs.rs b/fusio/src/dynamic/fs.rs index 5d96bf2..4d06444 100644 --- a/fusio/src/dynamic/fs.rs +++ b/fusio/src/dynamic/fs.rs @@ -1,8 +1,6 @@ use std::{cmp, pin::Pin, sync::Arc}; -use futures_core::Stream; - -use super::MaybeSendFuture; +use super::{MaybeSendFuture, MaybeSendStream}; use crate::{ buf::IoBufMut, fs::{FileMeta, FileSystemTag, Fs, OpenOptions}, @@ -75,7 +73,7 @@ pub trait DynFs: MaybeSend + MaybeSync { Box< dyn MaybeSendFuture< Output = Result< - Pin> + 's>>, + Pin> + 's>>, Error, >, > + 's, @@ -130,7 +128,7 @@ impl DynFs for F { Box< dyn MaybeSendFuture< Output = Result< - Pin> + 's>>, + Pin> + 's>>, Error, >, > + 's, @@ -138,7 +136,10 @@ impl DynFs for F { > { Box::pin(async move { let stream = F::list(self, path).await?; - Ok(Box::pin(stream) as Pin>>>) + Ok(Box::pin(stream) + as Pin< + Box>>, + >) }) } diff --git a/fusio/src/dynamic/mod.rs b/fusio/src/dynamic/mod.rs index 014c36b..bf43d8a 100644 --- a/fusio/src/dynamic/mod.rs +++ b/fusio/src/dynamic/mod.rs @@ -7,6 +7,7 @@ use std::{future::Future, pin::Pin}; #[cfg(feature = "fs")] pub use fs::{DynFile, DynFs}; +use futures_core::Stream; use crate::{ buf::{Slice, SliceMut}, @@ -17,6 +18,10 @@ pub trait MaybeSendFuture: Future + MaybeSend {} impl MaybeSendFuture for F where F: Future + MaybeSend {} +pub trait MaybeSendStream: Stream + MaybeSend {} + +impl MaybeSendStream for S where S: Stream + MaybeSend {} + pub trait DynWrite: MaybeSend { //! Dyn compatible(object safety) version of [`Write`]. //! All implementations of [`Write`] has already implemented this trait. diff --git a/fusio/src/fs/mod.rs b/fusio/src/fs/mod.rs index d0589d8..ea0381f 100644 --- a/fusio/src/fs/mod.rs +++ b/fusio/src/fs/mod.rs @@ -46,7 +46,8 @@ pub trait Fs: MaybeSend + MaybeSync { fn list( &self, path: &Path, - ) -> impl Future>, Error>> + MaybeSend; + ) -> impl Future> + MaybeSend, Error>> + + MaybeSend; fn remove(&self, path: &Path) -> impl Future> + MaybeSend;