Struct LockedSnapshot

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

Source

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
Source

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
Source

pub async fn reset(&mut self) -> Result<(), Error>

Rewinds the iterator over slots used by next.

§Errors
Source

pub async fn count(&mut self) -> Result<u32, Error>

Returns the number of slots in the inventory.

This method does not have any effect on the “current position” used by next and reset.

§Errors
Source

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.

§Errors

Auto Trait Implementations§

§

impl<'snapshot, 'invoker, 'buffer, B> Freeze for LockedSnapshot<'snapshot, 'invoker, 'buffer, B>

§

impl<'snapshot, 'invoker, 'buffer, B> RefUnwindSafe for LockedSnapshot<'snapshot, 'invoker, 'buffer, B>
where B: RefUnwindSafe,

§

impl<'snapshot, 'invoker, 'buffer, B> Send for LockedSnapshot<'snapshot, 'invoker, 'buffer, B>
where B: Send,

§

impl<'snapshot, 'invoker, 'buffer, B> Sync for LockedSnapshot<'snapshot, 'invoker, 'buffer, B>
where B: Sync,

§

impl<'snapshot, 'invoker, 'buffer, B> Unpin for LockedSnapshot<'snapshot, 'invoker, 'buffer, B>

§

impl<'snapshot, 'invoker, 'buffer, B> !UnwindSafe for LockedSnapshot<'snapshot, 'invoker, 'buffer, B>

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.