diff --git a/src/database/database_view.rs b/src/database/database_view.rs index 08d19b624..b72a24bbb 100644 --- a/src/database/database_view.rs +++ b/src/database/database_view.rs @@ -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> { database_view: &'a DatabaseView<'a>, document_ids: I, @@ -73,6 +73,10 @@ where D: DeserializeOwned, { type Item = Result>; + fn size_hint(&self) -> (usize, Option) { + self.document_ids.size_hint() + } + fn next(&mut self) -> Option { match self.document_ids.next() { 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, +{ } + +impl<'a, D, I> DoubleEndedIterator for DocumentIter<'a, D, I> +where D: DeserializeOwned, + I: DoubleEndedIterator + Iterator, +{ + fn next_back(&mut self) -> Option { + match self.document_ids.next_back() { + Some(id) => Some(self.database_view.retrieve_document(id)), + None => None + } + } +}