pub fn load_inventory<I: ItemType + for<'de> Deserialize<'de>>(
path: &str,
) -> Result<Inventory<I>, Box<dyn Error>>Expand description
Reads and deserialises an crate::items::inventory::Inventory from the
JSON file at path.
Zero counts and item_byte values decoded as I::default() or is_empty()
become empty slots at their original indexes. Live duplicate stacks are not
merged. Capacity must equal the slot vector length, and the total of each
item (by equality) must fit in u32.
§Parameters
path— filesystem path of the JSON file written bysave_inventory.
§Errors
Returns a boxed error if:
- Capacity/layout or item totals are invalid (
std::io::ErrorKind::InvalidData). - The file does not exist or cannot be read (
std::io::Error). - The file contents are not valid JSON or do not match the expected schema
(
serde_json::Error).
§Examples
use voxel_framework::items::{DefaultItem, load_inventory};
let inv = load_inventory::<DefaultItem>("saves/player.json")
.expect("failed to load inventory");
println!("iron ore: {}", inv.count_of(DefaultItem::IronOre));