Function put [src]

key and value are copied into the BufMap.

Prototype

pub fn put(self: *BufMap, key: []const u8, value: []const u8) !void

Parameters

self: *BufMapkey: []const u8value: []const u8

Source

pub fn put(self: *BufMap, key: []const u8, value: []const u8) !void { const value_copy = try self.copy(value); errdefer self.free(value_copy); const get_or_put = try self.hash_map.getOrPut(key); if (get_or_put.found_existing) { self.free(get_or_put.value_ptr.*); } else { get_or_put.key_ptr.* = self.copy(key) catch |err| { _ = self.hash_map.remove(key); return err; }; } get_or_put.value_ptr.* = value_copy; }