Count entries in a redb table by iterating (redb tables don't have a len() method).
(
txn: &redb::ReadTransaction,
table_def: TableDefinition<K, V>,
)
| 458 | |
| 459 | /// Count entries in a redb table by iterating (redb tables don't have a len() method). |
| 460 | pub(crate) fn count_table_entries<K: redb::Key + 'static, V: redb::Value + 'static>( |
| 461 | txn: &redb::ReadTransaction, |
| 462 | table_def: TableDefinition<K, V>, |
| 463 | ) -> RedbStoreResult<u64> { |
| 464 | let table = txn.open_table(table_def)?; |
| 465 | let mut count = 0u64; |
| 466 | let iter = table.iter()?; |
| 467 | for _ in iter { |
| 468 | count += 1; |
| 469 | } |
| 470 | Ok(count) |
| 471 | } |
| 472 | |
| 473 | #[cfg(test)] |
| 474 | #[path = "tests.rs"] |