Hello,
I'm fighting the type system to get the following done, restricting further and further as per the compiler recommendations, but I'm now stuck because entries isn't Send.
pub trait Entry : Send {
// ...
}
pub trait Storage: Send where Self: 'static {
type E: Entry;
fn entries(
&self,
dir_id: Option<&str>,
) -> impl std::future::Future<Output = Result<impl Iterator<Item = Result<Self::E>>>> + Send;
fn discover<'a>(
self: Arc<Self>,
dir_id: Option<&'a str>,
tx: Sender<Result<Self::E>>,
) -> BoxFuture<'a, Result<()>>
where
Self: 'a,
<Self as Storage>::E: 'static,
Self: Sync,
{
Box::pin(async move {
let this = self.clone();
let entries = this.entries(dir_id).await?;
for entry in entries {
let dir_id = {
let mut dir_id: Option<String> = None;
if let Ok(entry) = &entry {
if entry.is_dir() {
dir_id = Some(entry.id().to_owned());
}
}
dir_id
};
tx.send(entry).await.unwrap();
if let Some(dir_id) = dir_id {
let tx = tx.clone();
let this2 = this.clone();
tokio::spawn(async move {
this2.discover(Some(&dir_id), tx).await;
});
}
}
Ok(())
})
}
}
Is there a way to achieve this? If possible with less restrictions...