Skip to main content

Transaction

Struct Transaction 

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

Several writes staged beside their destinations, renamed over them in order on commit; a staged file that is never committed is removed when the transaction drops.

Implementations§

Source§

impl Transaction

Source

pub fn new() -> Self

An empty transaction.

Source

pub fn stage(&mut self, path: &Path, bytes: &[u8]) -> Result<()>

Stage bytes for path: written whole and synced beside the destination, which holds what it held until commit.

§Errors

Any I/O failure from creating or writing the staged file; the destination is untouched.

Source

pub const fn len(&self) -> usize

How many writes are staged.

Source

pub const fn is_empty(&self) -> bool

Whether nothing is staged.

Source

pub fn commit(self) -> Result<Vec<PathBuf>, Interrupted>

Rename every staged file over its destination, in staging order.

§Errors

The first rename that fails stops the commit; the result names every destination renamed before it. The remaining staged files are removed, so no destination is ever half-written.

Source

pub fn commit_stopping_at( self, stop: Option<&Path>, ) -> Result<Vec<PathBuf>, Interrupted>

Self::commit, stopped on purpose before the rename over stop, as if that rename had failed. This is the one seam the interruption proof needs: a rename cannot be made to fail from outside without a read failing first, and the proof is about what the tree holds after a commit that stopped part way.

§Errors

As Self::commit, plus the injected stop.

Trait Implementations§

Source§

impl Debug for Transaction

Source§

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

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

impl Default for Transaction

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Transaction

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§

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

Source§

type Output = T

Should always be Self
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.