Skip to main content

load_inventory

Function load_inventory 

Source
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 by save_inventory.

§Errors

Returns a boxed error if:

§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));