view examples/asyncdb/src/main.rs @ 583:b315ed595a1f

Make asyncdb usable
author Lewin Bormann <lbo@spheniscida.de>
date Wed, 28 Sep 2022 10:17:14 +0200
parents
children adcd81a99cee
line wrap: on
line source

use tokio::main;

use rusty_leveldb::{AsyncDB, Options};

#[main(flavor = "current_thread")]
async fn main() {
    let adb = AsyncDB::new("testdb", Options::default()).unwrap();

    assert!(adb.put("Hello".as_bytes().to_owned(), "World".as_bytes().to_owned()).await.is_ok());

    let r = adb.get("Hello".as_bytes().to_owned()).await;
    assert_eq!(r, Ok(Some("World".as_bytes().to_owned())));

    adb.flush().await.expect("flush()");
    adb.close().await.expect("close()");
}