pub enum Slot {
Empty,
Item(ItemStack),
}Expand description
An empty inventory slot or a complete non-empty item stack.
The item count is encoded first. Zero denotes Slot::Empty; a positive
count is followed by the item registry ID, component-add count,
component-remove count, typed added components, and removed component IDs.
§Examples
use mcproto_types::{
DataComponent, MaxDamageComponent, Slot, ItemStack, TypeCodec, VarInt,
};
let mut item = ItemStack::new(2, 5)?;
item.components_to_add.push(DataComponent::MaxDamage(
MaxDamageComponent { max_damage: VarInt(100) },
));
let slot = Slot::Item(item);
let mut encoded = Vec::new();
slot.encode(&mut encoded)?;
let mut input = encoded.as_slice();
assert_eq!(Slot::decode(&mut input)?, slot);Variants§
Empty
Encoded as an item count of zero with no following fields.
Item(ItemStack)
A positive item count followed by item and component-patch data.
Trait Implementations§
impl StructuralPartialEq for Slot
Auto Trait Implementations§
impl Freeze for Slot
impl RefUnwindSafe for Slot
impl Send for Slot
impl Sync for Slot
impl Unpin for Slot
impl UnsafeUnpin for Slot
impl UnwindSafe for Slot
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ContextualCodec for Twhere
T: TypeCodec,
impl<T> ContextualCodec for Twhere
T: TypeCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
_context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, _context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
Decodes this value using context supplied by its enclosing structure.