pub struct LockedSnapshot<'snapshot, 'invoker, 'buffer, B: Buffer> { /* private fields */ }
Expand description
A snapshot of the contents of an inventory on which methods can be invoked.
This type combines an inventory snapshot, an Invoker
that can be used to make method calls,
and a scratch buffer used to perform CBOR encoding and decoding. A value of this type can be
created by calling Snapshot::lock
, and it can be dropped to return the
borrow of the invoker and buffer to the caller so they can be reused for other purposes.
The 'snapshot
lifetime is the lifetime of the original snapshot. The 'invoker
lifetime is
the lifetime of the invoker. The 'buffer
lifetime is the lifetime of the buffer. The B
type
is the type of scratch buffer to use.
Implementations§
Source§impl<'snapshot, 'invoker, 'buffer, B: Buffer> LockedSnapshot<'snapshot, 'invoker, 'buffer, B>
impl<'snapshot, 'invoker, 'buffer, B: Buffer> LockedSnapshot<'snapshot, 'invoker, 'buffer, B>
Sourcepub async fn next(self) -> Result<Option<ItemStack<'buffer>>, Error>
pub async fn next(self) -> Result<Option<ItemStack<'buffer>>, Error>
Returns the next item stack in the snapshot.
If the next slot is empty, None
is returned.
The strings in the returned item stack point into, and therefore retain ownership of, the
scratch buffer. Consequently, the LockedSnapshot
is consumed and cannot be reused.
§Errors
BadComponent
BadInventorySlot
is returned if iteration has reached the end of the slots.TooManyDescriptors
Sourcepub async fn get(
self,
slot: NonZeroU32,
) -> Result<Option<ItemStack<'buffer>>, Error>
pub async fn get( self, slot: NonZeroU32, ) -> Result<Option<ItemStack<'buffer>>, Error>
Returns a specific item stack in the snapshot.
The slot
parameter ranges from 1 to the inventory size. If the slot
parameter is out of
range, None
is returned.
This method does not have any effect on the “current position” used by next
and reset
.
The strings in the returned item stack point into, and therefore retain ownership of, the
scratch buffer. Consequently, the LockedSnapshot
is consumed and cannot be reused.
§Errors
Sourcepub async fn count(&mut self) -> Result<u32, Error>
pub async fn count(&mut self) -> Result<u32, Error>
Sourcepub async fn get_all(self) -> Result<Vec<Option<ItemStack<'buffer>>>, Error>
pub async fn get_all(self) -> Result<Vec<Option<ItemStack<'buffer>>>, Error>
Returns all items in the inventory.
This method does not have any effect on the “current position” used by next
and reset
.
The strings in the returned item stacks point into, and therefore retain ownership of, the
scratch buffer. Consequently, the LockedSnapshot
is consumed and cannot be reused.