Crates.io | gdbm_compat |
lib.rs | gdbm_compat |
version | 0.1.1 |
source | src |
created_at | 2021-07-10 07:32:12.011224 |
updated_at | 2021-07-10 07:49:11.467296 |
description | binding of gdbm_compat(/usr/lib/libgdbm_compat.so) single file key-value database |
homepage | https://docs.rs/gdbm_compat |
repository | https://github.com/pymongo/gdbm_compat |
max_upload_size | |
id | 421019 |
size | 6,275 |
binding of /usr/lib/libgdbm_compat.so single file key-value database
check examples/insert_update_query_delete.rs
let db_filename = libc::tmpnam(std::ptr::null_mut());
let dbm_ptr = dbm_open(
db_filename,
libc::O_RDWR | libc::O_CREAT,
libc::S_IRUSR | libc::S_IWUSR,
);
dbm_close(dbm_ptr);
let mut key = *b"black\0";
let key_datum = datum {
dptr: key.as_mut_ptr().cast(),
dsize: key.len() as i32 - 1,
};
let mut black = Color::new(0, 0, 0);
let value_datum = datum {
dptr: (&mut black as *mut Color).cast(),
dsize: Color::SIZE as i32,
};
dbm_store(dbm_ptr, key_datum, value_datum, StoreMode::DBM_INSERT);
let value_datum = dbm_fetch(dbm_ptr, key_datum);
if !value_datum.dptr.is_null() {
let mut color = std::mem::zeroed::<Color>();
std::ptr::copy(
value_datum.dptr.cast(),
&mut color as *mut Color,
value_datum.dsize as usize,
);
assert_eq!(color, black);
}
if dbm_delete(dbm_ptr, key_datum) == 0 {
println!("delete success");
}