Skip to main content

Txn

Struct Txn 

Source
pub struct Txn { /* private fields */ }
Expand description

A set of writes that become visible all at once, or not at all.

A transaction reads the branch head once, when it is opened, and stages its writes privately. Txn::commit swaps the branch head to a new commit in one step, and fails with Error::Conflict if another writer moved the head meanwhile; the caller then retries. Dropping a transaction without committing is a rollback that leaves no commit, no head movement and no change to any sequence counter.

Implementations§

Source§

impl Txn

Source

pub fn branch(&self) -> &str

The branch this transaction writes to.

Source

pub fn base(&self) -> CommitId

The commit this transaction was opened against.

Source

pub fn is_empty(&self) -> bool

Whether anything has been staged yet.

Source

pub fn put(&mut self, key: &str, value: Value) -> Result<()>

Stage a write.

Source

pub fn delete(&mut self, key: &str) -> Result<()>

Stage a delete.

Source

pub fn get(&self, key: &str) -> Option<Arc<Entry>>

Read a key as this transaction sees it: staged writes first, then the branch as it stood when the transaction was opened.

Source

pub fn rollback(self)

Discard every staged write. Equivalent to dropping the transaction, and spelled out for callers who want the intent on the page.

Source

pub fn commit(self, message: Option<String>) -> Result<CommitId>

Apply every staged write as one commit and move the branch head.

A transaction that stages nothing, or whose writes all turn out to be no-ops, creates no commit and returns the unchanged head.

Trait Implementations§

Source§

impl Debug for Txn

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Txn

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Txn

§

impl !UnwindSafe for Txn

§

impl Freeze for Txn

§

impl Send for Txn

§

impl Sync for Txn

§

impl Unpin for Txn

§

impl UnsafeUnpin for Txn

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.