pub struct InventoryTransaction { /* private fields */ }Expand description
Transaction type for Inventory.
The output type is the change notification which should be passed on after commit, if any change is made.
Implementations§
Source§impl InventoryTransaction
impl InventoryTransaction
Sourcepub fn insert<S: Into<Slot>, I: IntoIterator<Item = S>>(stacks: I) -> Self
pub fn insert<S: Into<Slot>, I: IntoIterator<Item = S>>(stacks: I) -> Self
Transaction to insert items/stacks into an inventory, which will fail if there is not sufficient space.
Sourcepub fn replace(slot: Ix, old: Slot, new: Slot) -> Self
pub fn replace(slot: Ix, old: Slot, new: Slot) -> Self
Transaction to replace the contents of an existing slot in an inventory, which will fail if the existing slot is not as expected.
TODO: Right now, this requires an exact match. In the future, we should be able to compose multiple modifications like “add 1 item to stack” ×2 into “add 2 items”.
Trait Implementations§
Source§impl Clone for InventoryTransaction
impl Clone for InventoryTransaction
Source§fn clone(&self) -> InventoryTransaction
fn clone(&self) -> InventoryTransaction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for InventoryTransaction
impl Debug for InventoryTransaction
Source§impl Default for InventoryTransaction
impl Default for InventoryTransaction
Source§fn default() -> InventoryTransaction
fn default() -> InventoryTransaction
Returns the “default value” for a type. Read more
Source§impl Merge for InventoryTransaction
impl Merge for InventoryTransaction
Source§type MergeCheck = ()
type MergeCheck = ()
Type of a value passed from
Merge::check_merge to Merge::commit_merge.
This may be used to pass precalculated values to speed up the merge phase,
but also makes it difficult to accidentally merge without checking.Source§type Conflict = InventoryConflict
type Conflict = InventoryConflict
Error type giving the reason why a merge was not possible. Read more
Source§fn check_merge(&self, other: &Self) -> Result<Self::MergeCheck, Self::Conflict>
fn check_merge(&self, other: &Self) -> Result<Self::MergeCheck, Self::Conflict>
Checks whether two transactions can be merged into a single transaction.
If so, returns
Ok containing data which may be passed to Self::commit_merge(). Read moreSource§fn commit_merge(&mut self, other: Self, (): Self::MergeCheck)
fn commit_merge(&mut self, other: Self, (): Self::MergeCheck)
Combines
other into self so that it has both effects simultaneously.
This operation must be commutative and have Default::default() as the identity. Read moreSource§impl PartialEq for InventoryTransaction
impl PartialEq for InventoryTransaction
Source§impl Transaction for InventoryTransaction
impl Transaction for InventoryTransaction
Source§type Context<'a> = ()
type Context<'a> = ()
Data which must be passed when checking the transaction.
Use
() if none is needed.Source§type CommitCheck = Option<InventoryCheck>
type CommitCheck = Option<InventoryCheck>
Type of a value passed from
Transaction::check to Transaction::commit.
This may be used to pass precalculated values to speed up the commit phase,
or even lock guards or similar, but also makes it slightly harder to accidentally
call commit without check.Source§type Output = InventoryChange
type Output = InventoryChange
The results of a
Transaction::commit() or Transaction::execute().
Each commit may produce any number of these messages. Read moreSource§type Mismatch = InventoryMismatch
type Mismatch = InventoryMismatch
Error type describing a precondition not met, returned by
Self::check(). Read moreSource§fn check(
&self,
inventory: &Inventory,
(): Self::Context<'_>,
) -> Result<Self::CommitCheck, Self::Mismatch>
fn check( &self, inventory: &Inventory, (): Self::Context<'_>, ) -> Result<Self::CommitCheck, Self::Mismatch>
Source§fn commit(
self,
inventory: &mut Inventory,
check: Self::CommitCheck,
outputs: &mut dyn FnMut(Self::Output),
) -> Result<(), CommitError>
fn commit( self, inventory: &mut Inventory, check: Self::CommitCheck, outputs: &mut dyn FnMut(Self::Output), ) -> Result<(), CommitError>
Perform the mutations specified by this transaction. The
check value should have
been created by a prior call to Transaction::check(). Read moreimpl StructuralPartialEq for InventoryTransaction
Auto Trait Implementations§
impl Freeze for InventoryTransaction
impl RefUnwindSafe for InventoryTransaction
impl Send for InventoryTransaction
impl Sync for InventoryTransaction
impl Unpin for InventoryTransaction
impl UnwindSafe for InventoryTransaction
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
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
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>
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 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>
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 moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.