Struct nut::Bucket

source ·
pub struct Bucket { /* private fields */ }
Expand description

Bucket represents a collection of key/value pairs inside the database.

Implementations§

source§

impl Bucket

source

pub fn tx(&self) -> Result<Tx, Error>

source

pub fn db(&self) -> Result<DB, Error>

source

pub fn root(&self) -> u64

source

pub fn cursor(&self) -> Result<Cursor<'_, &Bucket>, Error>

Creates a cursor associated with the bucket.

source

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.

source

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.

source

pub fn create_bucket(&mut self, key: &[u8]) -> Result<&mut Bucket, Error>

Creates bucket

source

pub fn create_bucket_if_not_exists( &mut self, key: &[u8] ) -> Result<&mut Bucket, Error>

Creates bucket if it not exists

source

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

source

pub fn buckets(&self) -> Vec<Vec<u8>>

Returns list of subbuckets’ keys

source

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"[..]);
source

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()
source

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()
source

pub fn sequence(&self) -> u64

Returns the current integer for the bucket without incrementing it.

source

pub fn next_sequence(&mut self) -> Result<u64, Error>

Returns an autoincrementing integer for the bucket.

source

pub fn set_sequence(&mut self, value: u64) -> Result<(), Error>

Updates the sequence number for the bucket.

source

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.

source

pub fn stats(&self) -> BucketStats

Returns stats on a bucket.

Trait Implementations§

source§

impl Debug for Bucket

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.