async-skipdb 0.2.1

An embedded, in-memory, zero-copy, atomicity, consistency, MVCC, almost lock-free and serializable snapshot isolation database engine.
Documentation
use async_skipdb::optimistic::TokioOptimisticDb;

#[derive(Debug)]
struct Person {
  hobby: String,
  age: u8,
}

#[tokio::main]
async fn main() {
  let db: TokioOptimisticDb<String, Person> = TokioOptimisticDb::new().await;

  {
    let alice = Person {
      hobby: "swim".to_string(),
      age: 20,
    };
    let bob = Person {
      hobby: "run".to_string(),
      age: 30,
    };

    let mut txn = db.write().await;
    txn.insert("Alice".to_string(), alice).unwrap();
    txn.insert("Bob".to_string(), bob).unwrap();

    {
      let alice = txn.get("Alice").unwrap().unwrap();
      assert_eq!(alice.value().age, 20);
      assert_eq!(alice.value().hobby, "swim");
    }

    {
      // output:
      // Alice:Person { hobby: "swim", age: 20 }
      // Bob:Person { hobby: "run", age: 30 }
      for ent in txn.iter().unwrap() {
        println!("{}:{:?}", ent.key(), ent.value());
      }

      // output:
      // Bob:Person { hobby: "run", age: 30 }
      // Alice:Person { hobby: "swim", age: 20 }
      for ent in txn.iter_rev().unwrap() {
        println!("{}:{:?}", ent.key(), ent.value());
      }

      // output:
      // Bob:Person { hobby: "run", age: 30 }
      for ent in txn.range("B".to_string()..).unwrap() {
        println!("{}:{:?}", ent.key(), ent.value());
      }

      // output:
      // Alice:Person { hobby: "swim", age: 20 }
      for ent in txn.range_rev(..="B".to_string()).unwrap() {
        println!("{}:{:?}", ent.key(), ent.value());
      }
    }

    txn.commit().await.unwrap();
  }

  {
    let txn = db.read().await;
    let alice = txn.get("Alice").unwrap();
    assert_eq!(alice.value().age, 20);
    assert_eq!(alice.value().hobby, "swim");

    let bob = txn.get("Bob").unwrap();
    assert_eq!(bob.value().age, 30);
    assert_eq!(bob.value().hobby, "run");

    // output:
    // Alice:Person { hobby: "swim", age: 20 }
    // Bob:Person { hobby: "run", age: 30 }
    for ent in txn.iter() {
      println!("{}:{:?}", ent.key(), ent.value());
    }

    // output:
    // Bob:Person { hobby: "run", age: 30 }
    // Alice:Person { hobby: "swim", age: 20 }
    for ent in txn.iter_rev() {
      println!("{}:{:?}", ent.key(), ent.value());
    }

    // output:
    // Bob:Person { hobby: "run", age: 30 }
    for ent in txn.range("B".to_string()..) {
      println!("{}:{:?}", ent.key(), ent.value());
    }

    // output:
    // Alice:Person { hobby: "swim", age: 20 }
    for ent in txn.range(..="B".to_string()) {
      println!("{}:{:?}", ent.key(), ent.value());
    }
  }
}