changeset 72:ca2c0b512210

Better comments for LdbIterator
author Lewin Bormann <lbo@spheniscida.de>
date Fri, 15 Jul 2016 20:11:32 +0200
parents 2f016fa1f063
children 416a07a89e9d
files src/types.rs
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/types.rs	Fri Jul 15 20:11:13 2016 +0200
+++ b/src/types.rs	Fri Jul 15 20:11:32 2016 +0200
@@ -40,13 +40,20 @@
 
 /// An extension of the standard `Iterator` trait that supports some methods necessary for LevelDB.
 /// This works because the iterators used are stateful and keep the last returned element.
+///
+/// Note: Implementing types are expected to hold `!valid()` before the first call to `next()`.
 pub trait LdbIterator<'a>: Iterator {
     // We're emulating LevelDB's Slice type here using actual slices with the lifetime of the
     // iterator. The lifetime of the iterator is usually the one of the backing storage (Block,
     // MemTable, SkipMap...)
     // type Item = (&'a [u8], &'a [u8]);
+
+    /// Seek the iterator to `key` or the next bigger key.
     fn seek(&mut self, key: &[u8]);
+    /// Returns true if `current()` would return a valid item.
     fn valid(&self) -> bool;
+    /// Return the current item. Panics if `!valid()`.
     fn current(&'a self) -> Self::Item;
+    /// Go to the previous item.
     fn prev(&mut self) -> Option<Self::Item>;
 }