Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction<'a, 'pg, St> { /* private fields */ }
Expand description

Transaction for modifying properties within a PropertyGroup.

Transaction uses a type-state pattern where methods are only available in particular states. The lifecycle of a Transaction is:

  1. Begin in the TransactionReset state
  2. Call Transaction::start() to begin the transaction, transitioning to the TransactionStarted state.
  3. Call any number of methods to delete, add, or change properties. A given property may only have one entry in a single transaction.
  4. Either call Transaction::reset() (return to 1) or Transaction::commit() to commit the transaction. On success, transitions to the terminal TransactionCommitted state; on “out of date” (i.e., the property group was concurrently modified), transitions back to the reset state (1).

Implementations§

Source§

impl<'a, 'pg, St> Transaction<'a, 'pg, St>

Source

pub fn reset(self) -> Transaction<'a, 'pg, TransactionReset>

Reset the transaction, clearing any pending entries.

Source

pub fn is_empty(&self) -> bool

Returns true if this transaction has no entries.

Source§

impl<'a, 'pg> Transaction<'a, 'pg, TransactionReset>

Source

pub fn start( self, ) -> Result<Transaction<'a, 'pg, TransactionStarted>, TransactionBuildError>

Start the transaction.

Committing a transaction will return TransactionCommitResult::OutOfDate if the property group is modified between start() and commit().

Source§

impl<'a, 'pg> Transaction<'a, 'pg, TransactionStarted>

Source

pub fn property_delete( &mut self, name: &str, ) -> Result<(), TransactionBuildError>

Delete a property by name.

Source

pub fn property_new( &mut self, name: &str, value: ValueRef<'_>, ) -> Result<(), TransactionBuildError>

Add a new property with a single value.

§Errors

This method will fail if the property already exists. Consider Transaction::property_ensure() for “add or update” semantics.

Source

pub fn property_new_multiple<'b, I>( &mut self, name: &str, value_kind: ValueKind, values: I, ) -> Result<(), TransactionBuildError>
where I: IntoIterator<Item = ValueRef<'b>>,

Add a new property with the given values.

§Errors

This method will fail if the property already exists or if any element of values has a kind inconsistent with value_kind. Consider Transaction::property_ensure_multiple() for “add or update” semantics.

Source

pub fn property_change( &mut self, name: &str, value: ValueRef<'_>, ) -> Result<(), TransactionBuildError>

Change an existing property to have a single value.

§Errors

This method will fail if the property does not exist or if the type of value is not consistent with the existing property value(s). Consider Transaction::property_ensure() for “add or update” semantics.

Source

pub fn property_change_multiple<'b, I>( &mut self, name: &str, value_kind: ValueKind, values: I, ) -> Result<(), TransactionBuildError>
where I: IntoIterator<Item = ValueRef<'b>>,

Change an existing property to have the given values.

§Errors

This method will fail if the property does not exist, if any element of values has a kind inconsistent with value_kind, or if value_kind is not consistent with the existing property value(s). Consider Transaction::property_ensure_multiple() for “add or update” semantics.

Source

pub fn property_change_type( &mut self, name: &str, value: ValueRef<'_>, ) -> Result<(), TransactionBuildError>

Change an existing property to have a single value, changing its type if necessary.

§Errors

This method will fail if the property does not exist. Consider Transaction::property_ensure() for “add or update” semantics.

Source

pub fn property_change_type_multiple<'b, I>( &mut self, name: &str, value_kind: ValueKind, values: I, ) -> Result<(), TransactionBuildError>
where I: IntoIterator<Item = ValueRef<'b>>,

Change an existing property to have the given values, changing its type if necessary.

§Errors

This method will fail if the property does not exist or if any element of values has a kind inconsistent with value_kind. Consider Transaction::property_ensure_multiple() for “add or update” semantics.

Source

pub fn property_ensure( &mut self, name: &str, value: ValueRef<'_>, ) -> Result<(), TransactionBuildError>

Ensure a property exists with the given single value.

This method will create the property if it does not exist, and will change its value (and type if necessary) if it does.

Source

pub fn property_ensure_multiple<'b, I>( &mut self, name: &str, value_kind: ValueKind, values: I, ) -> Result<(), TransactionBuildError>
where I: IntoIterator<Item = ValueRef<'b>>,

Ensure a property exists with the given values.

This method will create the property if it does not exist, and will change its values (and type if necessary) if it does.

§Errors

Fails if any element of values has a kind inconsistent with value_kind.

Source

pub fn commit( self, ) -> Result<TransactionCommitResult<'a, 'pg>, TransactionCommitError>

Commit this transaction.

Trait Implementations§

Source§

impl<'a, 'pg, St: Debug> Debug for Transaction<'a, 'pg, St>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, 'pg, St> Freeze for Transaction<'a, 'pg, St>

§

impl<'a, 'pg, St> RefUnwindSafe for Transaction<'a, 'pg, St>

§

impl<'a, 'pg, St> !Send for Transaction<'a, 'pg, St>

§

impl<'a, 'pg, St> !Sync for Transaction<'a, 'pg, St>

§

impl<'a, 'pg, St> Unpin for Transaction<'a, 'pg, St>

§

impl<'a, 'pg, St> UnsafeUnpin for Transaction<'a, 'pg, St>

§

impl<'a, 'pg, St> !UnwindSafe for Transaction<'a, 'pg, St>

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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V