mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
feat: Implement DoubleEnded/ExactSizeIterator on DocumentIter
This commit is contained in:
parent
6f8dbbde9a
commit
6c7a6c5219
@ -60,7 +60,7 @@ impl<'a> DatabaseView<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO impl ExactSizeIterator, DoubleEndedIterator
|
// TODO this is just an iter::Map !!!
|
||||||
pub struct DocumentIter<'a, D, I> {
|
pub struct DocumentIter<'a, D, I> {
|
||||||
database_view: &'a DatabaseView<'a>,
|
database_view: &'a DatabaseView<'a>,
|
||||||
document_ids: I,
|
document_ids: I,
|
||||||
@ -73,6 +73,10 @@ where D: DeserializeOwned,
|
|||||||
{
|
{
|
||||||
type Item = Result<D, Box<Error>>;
|
type Item = Result<D, Box<Error>>;
|
||||||
|
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
self.document_ids.size_hint()
|
||||||
|
}
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match self.document_ids.next() {
|
match self.document_ids.next() {
|
||||||
Some(id) => Some(self.database_view.retrieve_document(id)),
|
Some(id) => Some(self.database_view.retrieve_document(id)),
|
||||||
@ -80,3 +84,20 @@ where D: DeserializeOwned,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, D, I> ExactSizeIterator for DocumentIter<'a, D, I>
|
||||||
|
where D: DeserializeOwned,
|
||||||
|
I: ExactSizeIterator + Iterator<Item=DocumentId>,
|
||||||
|
{ }
|
||||||
|
|
||||||
|
impl<'a, D, I> DoubleEndedIterator for DocumentIter<'a, D, I>
|
||||||
|
where D: DeserializeOwned,
|
||||||
|
I: DoubleEndedIterator + Iterator<Item=DocumentId>,
|
||||||
|
{
|
||||||
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
|
match self.document_ids.next_back() {
|
||||||
|
Some(id) => Some(self.database_view.retrieve_document(id)),
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user