ThreadUser said:
5 messages · –R 🍳 const std = @import("std"); const allocator = std.heap.c_allocator; pub fn main() !void { // 省略 // The put() function returns the old entry const old_entry = try map.put(key, value2); std.debug.print("Replaced with value: {d}\n", .{value2.*}); // 3. Manually free the old value if (old_entry) |entry| { std.debug.print("Old value was: {d}\n", .{entry.value.*}); allocator.destroy(entry.value); // You MUST do this! } }🍳
M