diff --git a/src/database/map.rs b/src/database/map.rs index 9229d7a9..0a628f9c 100644 --- a/src/database/map.rs +++ b/src/database/map.rs @@ -130,28 +130,37 @@ impl Map { } pub fn iter_from<'a>(&'a self, from: &[u8], backwards: bool) -> Box + 'a> { + let direction = if backwards { + Direction::Reverse + } else { + Direction::Forward + }; + let mode = IteratorMode::From(from, direction); let read_options = read_options_default(); let it = self .db .db - .iterator_cf_opt( - &self.cf(), - read_options, - IteratorMode::From( - from, - if backwards { - Direction::Reverse - } else { - Direction::Forward - }, - ), - ) + .iterator_cf_opt(&self.cf(), read_options, mode) .map(Result::unwrap) .map(|(k, v)| (Vec::from(k), Vec::from(v))); Box::new(it) } + pub fn scan_prefix<'a>(&'a self, prefix: Vec) -> Box + 'a> { + let mode = IteratorMode::From(&prefix, Direction::Forward); + let read_options = read_options_default(); + let it = self + .db + .db + .iterator_cf_opt(&self.cf(), read_options, mode) + .map(Result::unwrap) + .map(|(k, v)| (Vec::from(k), Vec::from(v))) + .take_while(move |(k, _)| k.starts_with(&prefix)); + + Box::new(it) + } + pub fn increment(&self, key: &[u8]) -> Result> { let read_options = &self.read_options; let old = self @@ -202,19 +211,6 @@ impl Map { Ok(()) } - pub fn scan_prefix<'a>(&'a self, prefix: Vec) -> Box + 'a> { - let read_options = read_options_default(); - let it = self - .db - .db - .iterator_cf_opt(&self.cf(), read_options, IteratorMode::From(&prefix, Direction::Forward)) - .map(Result::unwrap) - .map(|(k, v)| (Vec::from(k), Vec::from(v))) - .take_while(move |(k, _)| k.starts_with(&prefix)); - - Box::new(it) - } - pub fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin + Send + 'a>> { self.watchers.watch(prefix) }