pub trait ReadableTable<K: RedbKey + 'static, V: RedbValue + 'static>: Sealed {
// Required methods
fn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<AccessGuard<'_, V>>, StorageError>
where K: 'a;
fn range<'a, KR>(
&self,
range: impl RangeBounds<KR> + 'a,
) -> Result<Range<'_, K, V>, StorageError>
where K: 'a,
KR: Borrow<K::SelfType<'a>> + 'a;
fn stats(&self) -> Result<TableStats, StorageError>;
fn len(&self) -> Result<u64, StorageError>;
fn is_empty(&self) -> Result<bool, StorageError>;
// Provided methods
fn first(
&self,
) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>, StorageError> { ... }
fn last(
&self,
) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>, StorageError> { ... }
fn iter(&self) -> Result<Range<'_, K, V>, StorageError> { ... }
}
Required Methods§
Sourcefn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<AccessGuard<'_, V>>, StorageError>where
K: 'a,
fn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<AccessGuard<'_, V>>, StorageError>where
K: 'a,
Returns the value corresponding to the given key
Sourcefn range<'a, KR>(
&self,
range: impl RangeBounds<KR> + 'a,
) -> Result<Range<'_, K, V>, StorageError>
fn range<'a, KR>( &self, range: impl RangeBounds<KR> + 'a, ) -> Result<Range<'_, K, V>, StorageError>
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 = 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());
Sourcefn stats(&self) -> Result<TableStats, StorageError>
fn stats(&self) -> Result<TableStats, StorageError>
Retrieves information about storage usage for the table
Sourcefn len(&self) -> Result<u64, StorageError>
fn len(&self) -> Result<u64, StorageError>
Returns the number of entries in the table
Sourcefn is_empty(&self) -> Result<bool, StorageError>
fn is_empty(&self) -> Result<bool, StorageError>
Returns true
if the table is empty
Provided Methods§
Sourcefn first(
&self,
) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>, StorageError>
fn first( &self, ) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>, StorageError>
Returns the first key-value pair in the table, if it exists
Sourcefn last(
&self,
) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>, StorageError>
fn last( &self, ) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>, StorageError>
Returns the last key-value pair in the table, if it exists
Sourcefn iter(&self) -> Result<Range<'_, K, V>, StorageError>
fn iter(&self) -> Result<Range<'_, K, V>, StorageError>
Returns a double-ended iterator over all elements in the table
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.