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.
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, remove_at_slot, and get_slot support drag-and-drop UI integration, plus has_room_for capacity queries and case-insensitive search.
Serde all the way
Inventory and ItemStack derive Serialize / Deserialize for save files, network sync, and FFI snapshots (behind the snapshot feature).
Optional Bevy plugin
The bevy feature adds InventoryPlugin, LootEvent / InventoryFullEvent observers, and SplitStackAction / MergeStackAction / MoveSlotAction UI actions.
Get started
Usage
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 works, but the crate can run 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.