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>§
Sourcepub fn cursor(&self) -> Cursor<'_, RwLockWriteGuard<'_, Bucket>>
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.
pub fn stats(&self) -> TxStats
Sourcepub fn bucket(
&self,
key: &[u8],
) -> Result<MappedRwLockReadGuard<'_, Bucket>, Error>
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.
Sourcepub fn for_each<'a, E: Into<Error>>(
&self,
handler: Box<dyn FnMut(&[u8], Option<&Bucket>) -> Result<(), E> + 'a>,
) -> Result<(), Error>
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
Sourcepub fn write_to<W: Write>(&self, w: W) -> Result<i64, Error>
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.
Sourcepub fn copy_to(&self, path: &str, mode: OpenOptions) -> Result<(), Error>
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.
Sourcepub fn rollback(&self) -> Result<(), Error>
pub fn rollback(&self) -> Result<(), Error>
Closes the transaction and ignores all previous updates. Read-only transactions must be rolled back and not committed.
Sourcepub fn check_sync(&self) -> Result<(), Error>
pub fn check_sync(&self) -> Result<(), Error>
Sync version of check()
In case of checking thread panic will also return Error
pub fn check(&self) -> Receiver<String>
pub fn freed(&self) -> Result<HashMap<u64, bool>, Error>
Trait Implementations§
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> 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