Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

put

Public Function
std.process.Environ.Map.put
pub fn put(self: *Map, key: []const u8, value: []const u8) Allocator.Error!void

key and value are copied into the Map.

Asserts that key is valid:

  • It cannot contain a NUL ('\x00') byte.
  • It must have a length > 0.
  • It cannot contain =, except on Windows where only the first code point is allowed to be =.
  • On Windows, it must be valid WTF-8.

Params

  • self: *Map
  • key: []const u8
  • value: []const u8

File

process/Environ.zig:257
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
    pub fn put(self: *Map, key: []const u8, value: []const u8) Allocator.Error!void {
        assert(validateKeyForPut(key));
        const gpa = self.allocator;
        const value_copy = try gpa.dupe(u8, value);
        errdefer gpa.free(value_copy);
        const get_or_put = try self.array_hash_map.getOrPut(gpa, key);
        errdefer {
            if (!get_or_put.found_existing) assert(self.array_hash_map.pop() != null);
        }
        if (get_or_put.found_existing) {
            gpa.free(get_or_put.value_ptr.*);
        } else {
            get_or_put.key_ptr.* = try gpa.dupe(u8, key);
        }
        get_or_put.value_ptr.* = value_copy;
    }