Skip to content

Commit

Permalink
feat: refactor implement MaybeSend for fs::list returning stream
Browse files Browse the repository at this point in the history
  • Loading branch information
ethe committed Dec 18, 2024
1 parent 216eb44 commit 7029eba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 7 additions & 6 deletions fusio/src/dynamic/fs.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -75,7 +73,7 @@ pub trait DynFs: MaybeSend + MaybeSync {
Box<
dyn MaybeSendFuture<
Output = Result<
Pin<Box<dyn Stream<Item = Result<FileMeta, Error>> + 's>>,
Pin<Box<dyn MaybeSendStream<Item = Result<FileMeta, Error>> + 's>>,
Error,
>,
> + 's,
Expand Down Expand Up @@ -130,15 +128,18 @@ impl<F: Fs> DynFs for F {
Box<
dyn MaybeSendFuture<
Output = Result<
Pin<Box<dyn Stream<Item = Result<FileMeta, Error>> + 's>>,
Pin<Box<dyn MaybeSendStream<Item = Result<FileMeta, Error>> + 's>>,
Error,
>,
> + 's,
>,
> {
Box::pin(async move {
let stream = F::list(self, path).await?;
Ok(Box::pin(stream) as Pin<Box<dyn Stream<Item = Result<FileMeta, Error>>>>)
Ok(Box::pin(stream)
as Pin<
Box<dyn MaybeSendStream<Item = Result<FileMeta, Error>>>,
>)
})
}

Expand Down
5 changes: 5 additions & 0 deletions fusio/src/dynamic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -17,6 +18,10 @@ pub trait MaybeSendFuture: Future + MaybeSend {}

impl<F> MaybeSendFuture for F where F: Future + MaybeSend {}

pub trait MaybeSendStream: Stream + MaybeSend {}

impl<S> 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.
Expand Down
3 changes: 2 additions & 1 deletion fusio/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub trait Fs: MaybeSend + MaybeSync {
fn list(
&self,
path: &Path,
) -> impl Future<Output = Result<impl Stream<Item = Result<FileMeta, Error>>, Error>> + MaybeSend;
) -> impl Future<Output = Result<impl Stream<Item = Result<FileMeta, Error>> + MaybeSend, Error>>
+ MaybeSend;

fn remove(&self, path: &Path) -> impl Future<Output = Result<(), Error>> + MaybeSend;

Expand Down

0 comments on commit 7029eba

Please sign in to comment.