1 个不稳定版本
0.1.0 | 2021年7月20日 |
---|
#64 在 #hash-table
4KB
迅鹰DB
迅鹰DB 是一个用于 Rust 的内存线程安全数据存储库。
用法
在 cargo.toml 中
[dependencies]
peregrine_db = {git = "https://github.com/MarshallBelles/PeregrineDB"}
在 .rs 中
use peregrine_db::PeregrineDB;
use std::collections::HashMap;
use futures::executor::block_on;
#[macro_use]
extern crate log;
async fn peregrine_example() {
// initialize new DB
let db: PeregrineDB = PeregrineDB::new();
info!("PeregrineDB initialized");
// save some data
let mut data = HashMap::new();
data.insert("hello".to_string(), "world".to_string());
let response = db.write(data).await.unwrap();
info!("Saved data");
// read the data
let mut keys = vec![];
keys.push("hello".to_string());
let stored_data = db.read(keys).await.unwrap();
info!("Read data");
// write and read should be the same
assert_eq!(stored_data, response);
info!("{:?} == {:?}", stored_data, response);
}
fn main() {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"));
block_on(peregrine_example());
}
输出
user@localhost example % cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
Running `target/debug/example`
[2021-07-19T19:49:21Z INFO example] PeregrineDB initialized
[2021-07-19T19:49:21Z INFO example] Saved data
[2021-07-19T19:49:21Z INFO example] Read data
[2021-07-19T19:49:21Z INFO example] {"hello": "world"} == {"hello": "world"}
依赖项
~1.5MB
~37K SLoC