Trait redb::ReadableTable

source ·
pub trait ReadableTable<K: RedbKey + 'static, V: RedbValue + 'static> {
    fn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>
) -> Result<Option<AccessGuard<'_, V>>, Error>
where
K: 'a
; fn range<'a: 'b, 'b, KR>(
&'a self,
range: impl RangeBounds<KR> + 'b
) -> Result<RangeIter<'a, K, V>, Error>
where
K: 'a,
KR: Borrow<K::SelfType<'b>> + 'b
; fn len(&self) -> Result<usize, Error>; fn is_empty(&self) -> Result<bool, Error>; fn iter(&self) -> Result<RangeIter<'_, K, V>, Error> { ... } }

Required Methods§

source

fn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>
) -> Result<Option<AccessGuard<'_, V>>, Error>where
K: 'a,

Returns the value corresponding to the given key

source

fn range<'a: 'b, 'b, KR>(
&'a self,
range: impl RangeBounds<KR> + 'b
) -> Result<RangeIter<'a, K, V>, Error>where
K: 'a,
KR: Borrow<K::SelfType<'b>> + 'b,

Returns a double-ended iterator over a range of elements in the table

Examples

Usage:

use redb::*;
const TABLE: TableDefinition<&str, u64> = TableDefinition::new("my_data");

let db = unsafe { Database::create(filename)? };
let write_txn = db.begin_write()?;
{
    let mut table = write_txn.open_table(TABLE)?;
    table.insert("a", &0)?;
    table.insert("b", &1)?;
    table.insert("c", &2)?;
}
write_txn.commit()?;

let read_txn = db.begin_read()?;
let table = read_txn.open_table(TABLE)?;
let mut iter = table.range("a".."c")?;
let (key, value) = iter.next().unwrap();
assert_eq!("a", key.value());
assert_eq!(0, value.value());
source

fn len(&self) -> Result<usize, Error>

Returns the number of entries in the table

source

fn is_empty(&self) -> Result<bool, Error>

Returns true if the table is empty

Provided Methods§

source

fn iter(&self) -> Result<RangeIter<'_, K, V>, Error>

Returns a double-ended iterator over all elements in the table

Implementors§

source§

impl<'db, 'txn, K: RedbKey + 'static, V: RedbValue + 'static> ReadableTable<K, V> for Table<'db, 'txn, K, V>

source§

impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> ReadableTable<K, V> for ReadOnlyTable<'txn, K, V>