pub fn install_db_dir_lib(cx: &mut Cx) -> Result<Value>Expand description
Open a fresh db-directory store and return its root DbDir wrapped as an
opaque table/directory object.
§Errors
Returns a capability error if the table/db capability has not been granted
to cx. Note that the individual read, write, mkdir, and rmdir operations
on the returned directory are gated by their own capabilities.
§Examples
use std::sync::Arc;
use sim_kernel::{
Cx, DefaultFactory, EagerPolicy, Symbol, Table,
capability::{table_db_capability, table_db_read_capability, table_db_write_capability},
};
use sim_table_db::install_db_dir_lib;
let mut cx = Cx::new(Arc::new(EagerPolicy), Arc::new(DefaultFactory));
cx.grant(table_db_capability());
cx.grant(table_db_read_capability());
cx.grant(table_db_write_capability());
let root = install_db_dir_lib(&mut cx).unwrap();
let table = root.object().as_table_impl().unwrap();
let value = cx.factory().string("v".to_owned()).unwrap();
table.set(&mut cx, Symbol::new("k"), value.clone()).unwrap();
assert_eq!(table.get(&mut cx, Symbol::new("k")).unwrap(), value);