pub struct WriteBatchWithIndex { /* private fields */ }Expand description
A write batch that can also be read from, and that can be layered on top of a database iterator.
Values read out of the batch are copied, but iterators and pinned slices borrow, so the borrow checker is what keeps them from outliving their owner.
An iterator built with Self::iterator_with_base reads directly out of the
batch’s internal skip-list, so it cannot outlive the batch:
use rust_rocksdb::{DB, WriteBatchWithIndex};
let db = DB::open_default("foo").unwrap();
let mut iter = {
let mut wbwi = WriteBatchWithIndex::new(0, true);
wbwi.put(b"k", b"v");
wbwi.iterator_with_base(db.raw_iterator())
};
iter.seek_to_first();A slice from Self::get_pinned_from_batch_and_db pins a block in the
database’s block cache, so it cannot outlive the database:
use rust_rocksdb::{DB, ReadOptions, WriteBatchWithIndex};
let wbwi = WriteBatchWithIndex::new(0, true);
let readopts = ReadOptions::default();
let _value = {
let db = DB::open_default("foo").unwrap();
wbwi.get_pinned_from_batch_and_db(&db, b"k", &readopts).unwrap()
};Implementations§
Source§impl WriteBatchWithIndex
impl WriteBatchWithIndex
pub fn new(reserved_bytes: usize, overwrite_key: bool) -> Self
pub fn len(&self) -> usize
Sourcepub fn size_in_bytes(&self) -> usize
pub fn size_in_bytes(&self) -> usize
Return WriteBatch serialized size (in bytes).
Sourcepub fn data(&self) -> &[u8] ⓘ
pub fn data(&self) -> &[u8] ⓘ
Return a reference to a byte array which represents a serialized version of the batch.
pub fn is_empty(&self) -> bool
pub fn get_from_batch<K>( &self, key: K, options: &Options, ) -> Result<Option<Vec<u8>>, Error>
pub fn get_from_batch_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, options: &Options, ) -> Result<Option<Vec<u8>>, Error>
pub fn get_from_batch_and_db<T, I, K>( &self, db: &DBCommon<T, I>, key: K, readopts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>
Sourcepub fn get_pinned_from_batch_and_db<'db, T, I, K>(
&self,
db: &'db DBCommon<T, I>,
key: K,
readopts: &ReadOptions,
) -> Result<Option<DBPinnableSlice<'db>>, Error>
pub fn get_pinned_from_batch_and_db<'db, T, I, K>( &self, db: &'db DBCommon<T, I>, key: K, readopts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'db>>, Error>
The returned slice pins a block inside db’s block cache, so its
lifetime is tied to db rather than to self. Letting lifetime elision
pick &self here would allow the slice to outlive the database and
release a cache handle into a destroyed cache.
pub fn get_from_batch_and_db_cf<T, I, K>( &self, db: &DBCommon<T, I>, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>
Sourcepub fn get_pinned_from_batch_and_db_cf<'db, T, I, K>(
&self,
db: &'db DBCommon<T, I>,
cf: &impl AsColumnFamilyRef,
key: K,
readopts: &ReadOptions,
) -> Result<Option<DBPinnableSlice<'db>>, Error>
pub fn get_pinned_from_batch_and_db_cf<'db, T, I, K>( &self, db: &'db DBCommon<T, I>, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'db>>, Error>
The returned slice pins a block inside db’s block cache, so its
lifetime is tied to db rather than to self. See
Self::get_pinned_from_batch_and_db.
Sourcepub fn put<K, V>(&mut self, key: K, value: V)
pub fn put<K, V>(&mut self, key: K, value: V)
Insert a value into the database under the given key.
pub fn put_cf<K, V>(&mut self, cf: &impl AsColumnFamilyRef, key: K, value: V)
pub fn merge<K, V>(&mut self, key: K, value: V)
pub fn merge_cf<K, V>(&mut self, cf: &impl AsColumnFamilyRef, key: K, value: V)
Sourcepub fn delete<K: AsRef<[u8]>>(&mut self, key: K)
pub fn delete<K: AsRef<[u8]>>(&mut self, key: K)
Removes the database entry for key. Does nothing if the key was not found.
pub fn delete_cf<K: AsRef<[u8]>>(&mut self, cf: &impl AsColumnFamilyRef, key: K)
Sourcepub fn iterator_with_base<'a, D>(
&'a self,
base_iterator: DBRawIteratorWithThreadMode<'a, D>,
) -> DBRawIteratorWithThreadMode<'a, D>where
D: DBAccess,
pub fn iterator_with_base<'a, D>(
&'a self,
base_iterator: DBRawIteratorWithThreadMode<'a, D>,
) -> DBRawIteratorWithThreadMode<'a, D>where
D: DBAccess,
The returned iterator reads directly out of this batch’s internal
skip-list and write buffer, so it must not outlive the batch. Binding
&self to the same lifetime as the base iterator is what enforces that;
with an independent lifetime on &self the iterator could outlive the
batch and read freed memory.
Sourcepub fn iterator_with_base_cf<'a, D>(
&'a self,
base_iterator: DBRawIteratorWithThreadMode<'a, D>,
cf: &impl AsColumnFamilyRef,
) -> DBRawIteratorWithThreadMode<'a, D>where
D: DBAccess,
pub fn iterator_with_base_cf<'a, D>(
&'a self,
base_iterator: DBRawIteratorWithThreadMode<'a, D>,
cf: &impl AsColumnFamilyRef,
) -> DBRawIteratorWithThreadMode<'a, D>where
D: DBAccess,
The returned iterator reads directly out of this batch, so it must not
outlive the batch. See Self::iterator_with_base.