use crate::Result;
use async_trait::async_trait;
#[async_trait(?Send)]
pub trait AsyncDiscoveryIterator<T> {
async fn next(&mut self) -> Result<Option<T>>;
async fn collect_all(&mut self) -> Result<Vec<T>> {
let mut items = Vec::new();
while let Some(item) = self.next().await? {
items.push(item);
}
Ok(items)
}
async fn take(&mut self, n: usize) -> Result<Vec<T>> {
let mut items = Vec::with_capacity(n);
for _ in 0..n {
if let Some(item) = self.next().await? {
items.push(item);
} else {
break;
}
}
Ok(items)
}
}