pub struct DBRawIteratorWithThreadMode<'a, D>where
D: DBAccess,{ /* private fields */ }Expand description
A low-level iterator over a database or column family, created by DB::raw_iterator
and other raw_iterator_* methods.
This iterator replicates RocksDB’s API. It should provide better
performance and more features than DBIteratorWithThreadMode, which is a standard
Rust std::iter::Iterator.
use rust_rocksdb::{DB, Options};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage4")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage4.");
let path = tempdir.path();
{
let db = DB::open_default(path).unwrap();
let mut iter = db.raw_iterator();
// Forwards iteration
iter.seek_to_first();
while iter.valid() {
println!("Saw {:?} {:?}", iter.key(), iter.value());
iter.next();
}
// Reverse iteration
iter.seek_to_last();
while iter.valid() {
println!("Saw {:?} {:?}", iter.key(), iter.value());
iter.prev();
}
// Seeking
iter.seek(b"my key");
while iter.valid() {
println!("Saw {:?} {:?}", iter.key(), iter.value());
iter.next();
}
// Reverse iteration from key
// Note, use seek_for_prev when reversing because if this key doesn't exist,
// this will make the iterator start from the previous key rather than the next.
iter.seek_for_prev(b"my key");
while iter.valid() {
println!("Saw {:?} {:?}", iter.key(), iter.value());
iter.prev();
}
}
let _ = DB::destroy(&Options::default(), path);Implementations§
Source§impl<'a, D> DBRawIteratorWithThreadMode<'a, D>where
D: DBAccess,
impl<'a, D> DBRawIteratorWithThreadMode<'a, D>where
D: DBAccess,
Sourcepub fn valid(&self) -> bool
pub fn valid(&self) -> bool
Returns true if the iterator is valid. An iterator is invalidated when
it reaches the end of its defined range, or when it encounters an error.
To check whether the iterator encountered an error after valid has
returned false, use the status method. status will never
return an error when valid is true.
Sourcepub fn status(&self) -> Result<(), Error>
pub fn status(&self) -> Result<(), Error>
Returns an error Result if the iterator has encountered an error
during operation. When an error is encountered, the iterator is
invalidated and valid will return false when called.
Performing a seek will discard the current status.
Sourcepub fn seek_to_first(&mut self)
pub fn seek_to_first(&mut self)
Seeks to the first key in the database.
§Examples
use rust_rocksdb::{DB, Options};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage5")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage5.");
let path = tempdir.path();
{
let db = DB::open_default(path).unwrap();
let mut iter = db.raw_iterator();
// Iterate all keys from the start in lexicographic order
iter.seek_to_first();
while iter.valid() {
println!("{:?} {:?}", iter.key(), iter.value());
iter.next();
}
// Read just the first key
iter.seek_to_first();
if iter.valid() {
println!("{:?} {:?}", iter.key(), iter.value());
} else {
// There are no keys in the database
}
}
let _ = DB::destroy(&Options::default(), path);Sourcepub fn seek_to_last(&mut self)
pub fn seek_to_last(&mut self)
Seeks to the last key in the database.
§Examples
use rust_rocksdb::{DB, Options};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage6")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage6.");
let path = tempdir.path();
{
let db = DB::open_default(path).unwrap();
let mut iter = db.raw_iterator();
// Iterate all keys from the end in reverse lexicographic order
iter.seek_to_last();
while iter.valid() {
println!("{:?} {:?}", iter.key(), iter.value());
iter.prev();
}
// Read just the last key
iter.seek_to_last();
if iter.valid() {
println!("{:?} {:?}", iter.key(), iter.value());
} else {
// There are no keys in the database
}
}
let _ = DB::destroy(&Options::default(), path);Sourcepub fn seek<K>(&mut self, key: K)
pub fn seek<K>(&mut self, key: K)
Seeks to the specified key or the first key that lexicographically follows it.
This method will attempt to seek to the specified key. If that key does not exist, it will find and seek to the key that lexicographically follows it instead.
§Examples
use rust_rocksdb::{DB, Options};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage7")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage7.");
let path = tempdir.path();
{
let db = DB::open_default(path).unwrap();
let mut iter = db.raw_iterator();
// Read the first key that starts with 'a'
iter.seek(b"a");
if iter.valid() {
println!("{:?} {:?}", iter.key(), iter.value());
} else {
// There are no keys in the database
}
}
let _ = DB::destroy(&Options::default(), path);Sourcepub fn seek_for_prev<K>(&mut self, key: K)
pub fn seek_for_prev<K>(&mut self, key: K)
Seeks to the specified key, or the first key that lexicographically precedes it.
Like .seek() this method will attempt to seek to the specified key.
The difference with .seek() is that if the specified key do not exist, this method will
seek to key that lexicographically precedes it instead.
§Examples
use rust_rocksdb::{DB, Options};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage8")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage8.");
let path = tempdir.path();
{
let db = DB::open_default(path).unwrap();
let mut iter = db.raw_iterator();
// Read the last key that starts with 'a'
iter.seek_for_prev(b"b");
if iter.valid() {
println!("{:?} {:?}", iter.key(), iter.value());
} else {
// There are no keys in the database
}
}
let _ = DB::destroy(&Options::default(), path);Trait Implementations§
Source§impl<D> Drop for DBRawIteratorWithThreadMode<'_, D>where
D: DBAccess,
impl<D> Drop for DBRawIteratorWithThreadMode<'_, D>where
D: DBAccess,
impl<D> Send for DBRawIteratorWithThreadMode<'_, D>where
D: DBAccess,
impl<D> Sync for DBRawIteratorWithThreadMode<'_, D>where
D: DBAccess,
Auto Trait Implementations§
impl<'a, D> Freeze for DBRawIteratorWithThreadMode<'a, D>
impl<'a, D> RefUnwindSafe for DBRawIteratorWithThreadMode<'a, D>where
D: RefUnwindSafe,
impl<'a, D> Unpin for DBRawIteratorWithThreadMode<'a, D>
impl<'a, D> UnwindSafe for DBRawIteratorWithThreadMode<'a, D>where
D: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.