Skip to content
Viewing as a member
crates · rust · bevy

Slot-based inventory forbevy_inventory

A generic, slot-based inventory crate with item stacking, transfer, search, and serde-driven snapshots — a pure Rust core with optional Bevy ECS integration behind a feature flag.

Bring your own item enum

Unlike inventory crates that ship a fixed item type and a hard Bevy dependency, bevy_inventory lets you bring your own item enum and stays usable inside FFI cdylibs and headless consumers.

RustLanguage
0.1.0Version
OptionalBevy ECS
MITLicense

What it gives you

Features

Bring your own item enum

Implement ItemKind (with display_name and max_stack) and the crate handles the rest.

Automatic stacking

Items stack up to ItemKind::max_stack per slot, splitting across slots as needed within a configurable slot capacity.

Slot operations

swap_slots, split_stack, merge_slots, compact, and transfer between inventories support drag-and-drop UI, plus has_room_for capacity queries and case-insensitive search.

Serde all the way

Inventory and ItemStack derive Serialize / Deserialize for save files and network sync; the snapshot feature keeps a JSON copy of the live inventory that FFI hosts read with get_inventory_snapshot.

Optional Bevy plugin

The bevy feature adds InventoryPlugin, LootEvent / InventoryFullEvent observers, and SplitStackAction / MergeStackAction / MoveSlotAction UI actions.

Get started

Usage

main.rs
use bevy_inventory::{Inventory, ItemKind};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
enum Item { Wood, Stone, Gold }

impl ItemKind for Item {
    fn display_name(&self) -> &'static str {
        match self { Item::Wood => "Wood", Item::Stone => "Stone", Item::Gold => "Gold" }
    }
    fn max_stack(&self) -> u32 {
        match self { Item::Gold => 10, _ => u32::MAX }
    }
}

let mut inv = Inventory::<Item>::new(16);
inv.add(Item::Wood, 50);
inv.add(Item::Gold, 25);
assert_eq!(inv.count(Item::Gold), 25);

Questions

Frequently asked

What is the bevy_inventory crate?

bevy_inventory is a generic, slot-based inventory crate with item stacking, transfer, search, and serde-driven snapshots. It has a pure Rust core with optional Bevy ECS integration behind a feature flag.

Does bevy_inventory require Bevy?

No. The default build enables the bevy and snapshot features, but the crate runs as plain Rust with zero Bevy dependency when the bevy feature is disabled, which suits FFI cdylibs (uniti) and non-Bevy consumers like discordsh-bot.

How do I define custom item types?

Implement the ItemKind trait on your own item enum, providing display_name and max_stack. Items then stack automatically up to max_stack per slot, and every type round-trips through serde for save files and network sync.

Discuss on the forum

Questions, fixes and notes on this page live in the KBVE forum.