pub struct Bucket { /* private fields */ }Expand description
Bucket represents a collection of key/value pairs inside the database.
Implementations§
Source§impl Bucket
impl Bucket
pub fn tx(&self) -> Result<Tx, Error>
pub fn db(&self) -> Result<DB, Error>
pub fn root(&self) -> u64
Sourcepub fn cursor(&self) -> Result<Cursor<'_, &Bucket>, Error>
pub fn cursor(&self) -> Result<Cursor<'_, &Bucket>, Error>
Creates a cursor associated with the bucket.
Sourcepub fn bucket(&self, key: &[u8]) -> Option<&Bucket>
pub fn bucket(&self, key: &[u8]) -> Option<&Bucket>
Retrieves a nested bucket by name. Returns None if the bucket does not exist or found item is not bucket.
Sourcepub fn bucket_mut(&mut self, key: &[u8]) -> Option<&mut Bucket>
pub fn bucket_mut(&mut self, key: &[u8]) -> Option<&mut Bucket>
Retrieves a nested mutable bucket by name. Returns None if the bucket does not exist or found item is not bucket.
Sourcepub fn create_bucket_if_not_exists(
&mut self,
key: &[u8],
) -> Result<&mut Bucket, Error>
pub fn create_bucket_if_not_exists( &mut self, key: &[u8], ) -> Result<&mut Bucket, Error>
Creates bucket if it not exists
Sourcepub fn delete_bucket(&mut self, key: &[u8]) -> Result<(), Error>
pub fn delete_bucket(&mut self, key: &[u8]) -> Result<(), Error>
Removes bucket and its contents
Returns error if bucket not found or value is not bucket
Sourcepub fn get(&self, key: &[u8]) -> Option<&[u8]>
pub fn get(&self, key: &[u8]) -> Option<&[u8]>
Retrieves the value for a key in the bucket. Returns a None value if the key does not exist or if the key is a nested bucket.
§Example
use nut::DBBuilder;
let db = DBBuilder::new("./test.db").build().unwrap();
let tx = db.begin_tx().unwrap();
let flowers = tx.bucket(b"flowers").unwrap();
assert_eq!(flowers.get(b"irises").unwrap(), &b"Iris is a genus of species of flowering plants"[..]);Sourcepub fn put(&mut self, key: &[u8], value: Vec<u8>) -> Result<(), Error>
pub fn put(&mut self, key: &[u8], value: Vec<u8>) -> Result<(), Error>
Sets the value for a key in the bucket. If the key exist then its previous value will be overwritten. Returns an error if the bucket was created from a read-only transaction, if the key is blank, if the key is too large, or if the value is too large.
§Example
use nut::DBBuilder;
let mut db = DBBuilder::new("./test.db").build().unwrap();
let mut tx = db.begin_rw_tx().unwrap();
let mut flowers = tx.create_bucket(b"flowers").unwrap();
flowers.put(b"irises", b"Iris is a genus of species of flowering plants".to_vec()).unwrap()Sourcepub fn delete(&mut self, key: &[u8]) -> Result<(), Error>
pub fn delete(&mut self, key: &[u8]) -> Result<(), Error>
Removes a key from the bucket. If the key does not exist then nothing is done. Returns an error if the bucket was created from a read-only transaction.
§Example
use nut::DBBuilder;
let mut db = DBBuilder::new("./test.db").build().unwrap();
let mut tx = db.begin_rw_tx().unwrap();
let mut flowers = tx.bucket_mut(b"flowers").unwrap();
flowers.delete(b"irises").unwrap()Sourcepub fn sequence(&self) -> u64
pub fn sequence(&self) -> u64
Returns the current integer for the bucket without incrementing it.
Sourcepub fn next_sequence(&mut self) -> Result<u64, Error>
pub fn next_sequence(&mut self) -> Result<u64, Error>
Returns an autoincrementing integer for the bucket.
Sourcepub fn set_sequence(&mut self, value: u64) -> Result<(), Error>
pub fn set_sequence(&mut self, value: u64) -> Result<(), Error>
Updates the sequence number for the bucket.
Sourcepub fn for_each<'a, E: Into<Error>>(
&self,
handler: Box<dyn FnMut(&[u8], Option<&[u8]>) -> Result<(), E> + 'a>,
) -> Result<(), Error>
pub fn for_each<'a, E: Into<Error>>( &self, handler: Box<dyn FnMut(&[u8], Option<&[u8]>) -> Result<(), E> + 'a>, ) -> Result<(), Error>
Executes a function for each key/value pair in a bucket. If the provided function returns an error then the iteration is stopped and the error is returned to the caller.
Sourcepub fn stats(&self) -> BucketStats
pub fn stats(&self) -> BucketStats
Returns stats on a bucket.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Bucket
impl !RefUnwindSafe for Bucket
impl !Send for Bucket
impl !Sync for Bucket
impl Unpin for Bucket
impl !UnwindSafe for Bucket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more