use std::future::Future;
use std::ops::DerefMut;
use crate::raw::oio::Entry;
use crate::raw::*;
use crate::*;
pub type Lister = Box<dyn ListDyn>;
pub trait List: Unpin + Send + Sync {
fn next(&mut self) -> impl Future<Output = Result<Option<Entry>>> + MaybeSend;
}
impl List for () {
async fn next(&mut self) -> Result<Option<Entry>> {
Ok(None)
}
}
impl<P: List> List for Option<P> {
async fn next(&mut self) -> Result<Option<Entry>> {
match self {
Some(p) => p.next().await,
None => Ok(None),
}
}
}
pub trait ListDyn: Unpin + Send + Sync {
fn next_dyn(&mut self) -> BoxedFuture<'_, Result<Option<Entry>>>;
}
impl<T: List + ?Sized> ListDyn for T {
fn next_dyn(&mut self) -> BoxedFuture<'_, Result<Option<Entry>>> {
Box::pin(self.next())
}
}
impl<T: ListDyn + ?Sized> List for Box<T> {
async fn next(&mut self) -> Result<Option<Entry>> {
self.deref_mut().next_dyn().await
}
}