TxGuard

Struct TxGuard 

Source
pub struct TxGuard<'a> { /* private fields */ }
Expand description

Guard returned by DB.begin_tx()

Statically guards against outliving db and prevents from making mutable actions.

Implements Deref to Tx

Methods from Deref<Target = Tx>§

Source

pub fn writable(&self) -> bool

Returns whether the transaction can perform write operations.

Source

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

Creates a cursor associated with the root bucket. All items in the cursor will return a nil value because all items in root bucket are also buckets. The cursor is only valid as long as the transaction is open. Do not use a cursor after the transaction is closed.

Source

pub fn stats(&self) -> TxStats

Source

pub fn bucket( &self, key: &[u8], ) -> Result<MappedRwLockReadGuard<'_, Bucket>, Error>

Bucket retrieves a bucket by name. Returns None if the bucket does not exist. The bucket instance is only valid for the lifetime of the transaction.

Source

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

returns bucket keys for db

Source

pub fn for_each<'a, E: Into<Error>>( &self, handler: Box<dyn FnMut(&[u8], Option<&Bucket>) -> Result<(), E> + 'a>, ) -> Result<(), Error>

Executes a function for each bucket in the root. If the provided function returns an error then the iteration is stopped and the error is returned to the caller.

first argument of function is bucket’s key, second is bucket itself

Source

pub fn write_to<W: Write>(&self, w: W) -> Result<i64, Error>

Writes the entire database to a writer. If err == nil then exactly tx.Size() bytes will be written into the writer.

Source

pub fn copy_to(&self, path: &str, mode: OpenOptions) -> Result<(), Error>

Copies the entire database to file at the given path. A reader transaction is maintained during the copy so it is safe to continue using the database while a copy is in progress.

Source

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

Closes the transaction and ignores all previous updates. Read-only transactions must be rolled back and not committed.

Source

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

Sync version of check()

In case of checking thread panic will also return Error

Source

pub fn check(&self) -> Receiver<String>

Source

pub fn freed(&self) -> Result<HashMap<u64, bool>, Error>

Source

pub fn page_info(&self, id: usize) -> Result<Option<PageInfo>, Error>

Returns page information for a given page number. This is only safe for concurrent use when used by a writable transaction.

Trait Implementations§

Source§

impl<'a> Deref for TxGuard<'a>

Source§

type Target = Tx

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'a> Freeze for TxGuard<'a>

§

impl<'a> !RefUnwindSafe for TxGuard<'a>

§

impl<'a> Send for TxGuard<'a>

§

impl<'a> Sync for TxGuard<'a>

§

impl<'a> Unpin for TxGuard<'a>

§

impl<'a> !UnwindSafe for TxGuard<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.