1 unstable release

0.1.2 Oct 28, 2024

#1366 in Data structures

Download history 770/week @ 2024-10-28 855/week @ 2024-11-04 1137/week @ 2024-11-11 969/week @ 2024-11-18 1261/week @ 2024-11-25 681/week @ 2024-12-02 739/week @ 2024-12-09

3,717 downloads per month

MIT/Apache

130KB
3.5K SLoC

rotbl

read-only table


lib.rs:

Rotbl is a read-only on disk table of key-value.

use rotbl::v001::{Builder, Config, Rotbl, RotblMeta, SeqMarked};
#[tokio::main(flavor = "multi_thread")]
async fn main() {
let config = Config::default();
  #
  # // remove ./foo if exists
  # let _ = std::fs::remove_file("./foo");
  let r = {
    let mut b = Builder::new(config, "./foo").unwrap();

    // keys must be sorted
    b.append_kv("bar", SeqMarked::new_normal(1, b"bar".to_vec())).unwrap();
    b.append_kv("foo", SeqMarked::new_normal(2, b"foo".to_vec())).unwrap();

    Arc::new(b.commit(RotblMeta::new(1, "hello")).unwrap())
  };

  // Read the value back
  let val = r.get("foo").await.unwrap();
  assert_eq!(val, Some(SeqMarked::new_normal(2, b"foo".to_vec())));

  // Scan the table
  let kvs = r.range(..).try_collect::<Vec<_>>().await.unwrap();
  assert_eq!(kvs, vec![
                  ("bar".to_string(), SeqMarked::new_normal(1, b"bar".to_vec())),
                  ("foo".to_string(), SeqMarked::new_normal(2, b"foo".to_vec())),
  ]);
}

Dependencies

~7–14MB
~163K SLoC