use core::dict::Felt252Dict;
// A struct containing a Felt252Dict must implement Destruct
#[derive(Destruct, Default)]
struct ResourceManager {
resources: Felt252Dict,
count: u32,
}
#[generate_trait]
impl ResourceManagerImpl of ResourceManagerTrait{
fn add_resource(ref self: ResourceManager, resource_id: felt252, amount: u32){
assert!(self.resources.get(resource_id) == 0, "Resource already exists");
self.resources.insert(resource_id, amount);
self.count += amount;
}
}
let mut manager = Default::default();
// Add some resources
manager.add_resource(1, 100);
// When manager goes out of scope here, Destruct is automatically called,
// which ensures the dictionary is properly squashed