pub trait BucketApi<'tx>where
Self: Sized,{
// Required methods
fn root(&self) -> PgId;
fn writable(&self) -> bool;
fn cursor<'a>(&'a self) -> CursorImpl<'tx, 'a>;
fn bucket<'a, T: AsRef<[u8]>>(
&'a self,
name: T,
) -> Option<BucketImpl<'tx, 'a>>;
fn get<T: AsRef<[u8]>>(&self, key: T) -> Option<&[u8]>;
fn sequence(&self) -> u64;
fn for_each<F: FnMut(&'tx [u8], Option<&'tx [u8]>) -> Result<()>>(
&self,
f: F,
) -> Result<()>;
fn for_each_bucket<F: FnMut(&'tx [u8]) -> Result<()>>(
&self,
f: F,
) -> Result<()>;
fn stats(&self) -> BucketStats;
fn iter_entries<'a>(&'a self) -> EntryIter<'tx, 'a> ⓘ;
fn iter_buckets<'a>(&'a self) -> BucketIter<'tx, 'a> ⓘ;
}Expand description
Read-only Bucket API
Required Methods§
Sourcefn root(&self) -> PgId
fn root(&self) -> PgId
Returns the bucket’s root page id.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let mut b = tx.create_bucket_if_not_exists("test")?;
b.put("key", "value")?;
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
let page_id = b.root();
let page_info = tx.page(page_id).unwrap();
println!("{:?}", page_info);
Ok(())
})?;
Ok(())
}Sourcefn writable(&self) -> bool
fn writable(&self) -> bool
Returns whether the bucket is writable.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let b = tx.create_bucket_if_not_exists("test")?;
assert_eq!(true, b.writable());
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
assert_eq!(false, b.writable());
Ok(())
})?;
Ok(())
}Sourcefn cursor<'a>(&'a self) -> CursorImpl<'tx, 'a>
fn cursor<'a>(&'a self) -> CursorImpl<'tx, 'a>
Creates a cursor associated with the bucket.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let mut b = tx.create_bucket_if_not_exists("test")?;
b.put("key", "value")?;
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
let mut c = b.cursor();
let first = c.first();
assert_eq!(Some((b"key".as_slice(), Some(b"value".as_slice()))), first);
Ok(())
})?;
Ok(())
}Sourcefn bucket<'a, T: AsRef<[u8]>>(&'a self, name: T) -> Option<BucketImpl<'tx, 'a>>
fn bucket<'a, T: AsRef<[u8]>>(&'a self, name: T) -> Option<BucketImpl<'tx, 'a>>
Retrieves a nested bucket by name.
Returns None if the bucket does not exist.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let mut b = tx.create_bucket_if_not_exists("test")?;
let mut sub = b.create_bucket_if_not_exists("sub")?;
sub.put("key", "value")?;
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
assert_eq!(true, b.bucket("sub").is_some());
assert_eq!(false, b.bucket("no bucket").is_some());
Ok(())
})?;
Ok(())
}Sourcefn get<T: AsRef<[u8]>>(&self, key: T) -> Option<&[u8]>
fn get<T: AsRef<[u8]>>(&self, key: T) -> Option<&[u8]>
Retrieves the value for a key in the bucket.
Returns None if the key does not exist or if the key is a nested bucket.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let mut b = tx.create_bucket_if_not_exists("test")?;
b.put("key", "value")?;
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
let get = b.get("key");
assert_eq!(Some(b"value".as_slice()), get);
let get = b.get("no value");
assert_eq!(None, get);
Ok(())
})?;
Ok(())
}Sourcefn sequence(&self) -> u64
fn sequence(&self) -> u64
Returns the current integer for the bucket without incrementing it.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let mut b = tx.create_bucket_if_not_exists("test")?;
b.put("key", "value")?;
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
let seq = b.sequence();
assert_eq!(0, seq);
Ok(())
})?;
Ok(())
}Sourcefn for_each<F: FnMut(&'tx [u8], Option<&'tx [u8]>) -> Result<()>>(
&self,
f: F,
) -> Result<()>
👎Deprecated since 1.3.9: please use iter_* methods instead
fn for_each<F: FnMut(&'tx [u8], Option<&'tx [u8]>) -> Result<()>>( &self, f: F, ) -> Result<()>
iter_* methods insteadExecutes a function for each key/value pair in a bucket.
Because this uses a crate::CursorApi, the iteration over keys is in lexicographical order.
If the provided function returns an error then the iteration is stopped and the error is returned to the caller.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let mut b = tx.create_bucket_if_not_exists("test")?;
b.put("key1", "value1")?;
b.put("key2", "value2")?;
b.put("key3", "value3")?;
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
b.for_each(|k,v| {
println!("{:?}, {:?}", k, v);
Ok(())
})?;
Ok(())
})?;
Ok(())
}Sourcefn for_each_bucket<F: FnMut(&'tx [u8]) -> Result<()>>(&self, f: F) -> Result<()>
👎Deprecated since 1.3.9: please use iter_* methods instead
fn for_each_bucket<F: FnMut(&'tx [u8]) -> Result<()>>(&self, f: F) -> Result<()>
iter_* methods insteadExecutes a function for each bucket in a bucket.
Because this function uses a crate::CursorApi, the iteration over keys is in lexicographical order.
If the provided function returns an error then the iteration is stopped and the error is returned to the caller.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let mut b = tx.create_bucket_if_not_exists("test")?;
let _ = b.create_bucket_if_not_exists("sub1")?;
let _ = b.create_bucket_if_not_exists("sub2")?;
let _ = b.create_bucket_if_not_exists("sub3")?;
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
b.for_each_bucket(|k| {
println!("{:?}", k);
Ok(())
})?;
Ok(())
})?;
Ok(())
}Sourcefn stats(&self) -> BucketStats
fn stats(&self) -> BucketStats
Returns stats on a bucket.
use bbolt_rs::*;
fn main() -> Result<()> {
let mut db = Bolt::open_mem()?;
db.update(|mut tx| {
let mut b = tx.create_bucket_if_not_exists("test")?;
b.put("key1", "value1")?;
b.put("key2", "value2")?;
b.put("key3", "value3")?;
Ok(())
})?;
db.view(|tx| {
let b = tx.bucket("test").unwrap();
let stats = b.stats();
assert_eq!(3, stats.key_n());
Ok(())
})?;
Ok(())
}fn iter_entries<'a>(&'a self) -> EntryIter<'tx, 'a> ⓘ
fn iter_buckets<'a>(&'a self) -> BucketIter<'tx, 'a> ⓘ
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.