pub trait ReadableTable<K: Key + 'static, V: Value + 'static>: ReadableTableMetadata {
// Required methods
fn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<AccessGuard<'_, V>>>;
fn range<'a, KR>(
&self,
range: impl RangeBounds<KR> + 'a,
) -> Result<Range<'_, K, V>>
where KR: Borrow<K::SelfType<'a>> + 'a;
fn first(&self) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>;
fn last(&self) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>;
// Provided methods
fn get_bulk<'i, I>(
&self,
keys: I,
) -> Result<Vec<Option<AccessGuard<'_, V>>>>
where I: IntoIterator<Item = K::SelfType<'i>> { ... }
fn iter(&self) -> Result<Range<'_, K, V>> { ... }
}Required Methods§
Sourcefn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<AccessGuard<'_, V>>>
fn get<'a>( &self, key: impl Borrow<K::SelfType<'a>>, ) -> Result<Option<AccessGuard<'_, V>>>
Returns the value corresponding to the given key
Sourcefn range<'a, KR>(
&self,
range: impl RangeBounds<KR> + 'a,
) -> Result<Range<'_, K, V>>
fn range<'a, KR>( &self, range: impl RangeBounds<KR> + 'a, ) -> Result<Range<'_, K, V>>
Returns a double-ended iterator over a range of elements in the table
§Examples
Usage:
use manifold::*;
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 first(&self) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>
fn first(&self) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>
Returns the first key-value pair in the table, if it exists
Sourcefn last(&self) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>
fn last(&self) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>
Returns the last key-value pair in the table, if it exists
Provided Methods§
Sourcefn get_bulk<'i, I>(&self, keys: I) -> Result<Vec<Option<AccessGuard<'_, V>>>>where
I: IntoIterator<Item = K::SelfType<'i>>,
fn get_bulk<'i, I>(&self, keys: I) -> Result<Vec<Option<AccessGuard<'_, V>>>>where
I: IntoIterator<Item = K::SelfType<'i>>,
Retrieves multiple values in a single batch operation.
This method provides better performance than calling get() multiple times by:
- Optimizing B-tree traversal order (sorts keys internally)
- Reducing repeated lookups for nearby keys
- Better cache locality
§Arguments
keys- Iterator of keys to retrieve
§Returns
A vector of Option
§Examples
let keys = vec![1u64, 2u64, 3u64];
let values = table.get_bulk(keys.iter().copied())?;
for (i, value) in values.iter().enumerate() {
if let Some(guard) = value {
println!("Key {}: {:?}", keys[i], guard.value());
}
}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.