Skip to main content

BTree

Struct BTree 

Source
pub struct BTree { /* private fields */ }

Implementations§

Source§

impl BTree

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open or create a btree database at the given path.

Source

pub fn exec<F, R>(&self, bucket: &str, f: F) -> Result<R>
where F: FnOnce(&mut Txn<'_>) -> Result<R>,

Executes a read-write transaction on the specified bucket. Creates the bucket on successful commit if it doesn’t exist.

The transaction is committed if the closure returns Ok, but the commit can still fail (e.g., conflict or I/O error). On failure, changes are rolled back. If the closure returns Err, the transaction is rolled back (allocated pages are reclaimed).

§Warning

Nested calls to exec or view on the same BTree instance are NOT supported and may lead to deadlocks or undefined behavior.

Source

pub fn exec_multi<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&mut MultiTxn<'_>) -> Result<R>,

Executes multiple operations across different buckets in a single atomic transaction.

This is more efficient than calling exec multiple times because on success it performs a single superblock update and disk sync at the end.

Source

pub fn view<F, R>(&self, bucket: &str, f: F) -> Result<R>
where F: FnOnce(&ReadOnlyTxn<'_>) -> Result<R>,

Executes a read-only transaction on the specified bucket.

§Warning

Nested calls to exec or view on the same BTree instance are NOT supported and may lead to deadlocks or undefined behavior.

Source

pub fn del_bucket<N>(&self, name: N) -> Result<()>
where N: AsRef<str>,

Delete a bucket by name and persist the change.

Source

pub fn commit(&self) -> Result<()>

Commit pending catalog changes if no conflict is detected.

Source

pub fn compact(&self, target_bytes: u64) -> Result<CompactStats>

run tail-window compaction

target_bytes is the desired amount to reclaim, 0 uses the default ratio this moves live pages out of the tail window and tries to truncate the file if low-address free pages exceed the threshold, the mover allocates only below the tail

Source

pub fn buckets(&self) -> Result<Vec<String>>

Returns all bucket names.

Trait Implementations§

Source§

impl Clone for BTree

Source§

fn clone(&self) -> Self

Cloning a BTree handle shares the store, writer lock, and pending page tracking.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for BTree

§

impl !RefUnwindSafe for BTree

§

impl Send for BTree

§

impl Sync for BTree

§

impl Unpin for BTree

§

impl UnsafeUnpin for BTree

§

impl !UnwindSafe for BTree

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.