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. Private Type Function
Self
Private Type Function
std.enums.EnumArray.Self
pubfnEnumArray(comptimeE: type, comptimeV: type) type
An array keyed by an enum, backed by a dense array. If the enum is not dense, a mapping will be constructed from enum values to dense indices. This type does no dynamic allocation and can be copied by value.
pubfnEnumArray(comptimeE: type, comptimeV: type) type {
returnstruct {
constSelf = @This();
/// The index mapping for this mappubconstIndexer = EnumIndexer(E);
/// The key type used to index this mappubconstKey = Indexer.Key;
/// The value type stored in this mappubconstValue = V;
/// The number of possible keys in the mappubconstlen = Indexer.count;
values: [Indexer.count]Value,
pubfninit(init_values: EnumFieldStruct(E, Value, null)) Self {
returninitDefault(null, init_values);
}
/// Initializes values in the enum array, with the specified default.pubfninitDefault(comptimedefault: ?Value, init_values: EnumFieldStruct(E, Value, default)) Self {
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
varresult: Self = .{ .values = undefined };
inlinefor (0..Self.len) |i| {
constkey = comptimeIndexer.keyForIndex(i);
consttag = @tagName(key);
result.values[i] = @field(init_values, tag);
}
returnresult;
}
pubfninitUndefined() Self {
returnSelf{ .values = undefined };
}
pubfninitFill(v: Value) Self {
varself: Self = undefined;
@memset(&self.values, v);
returnself;
}
/// Returns the value in the array associated with a key.pubfnget(self: Self, key: Key) Value {
returnself.values[Indexer.indexOf(key)];
}
/// Returns a pointer to the slot in the array associated with a key.pubfngetPtr(self: *Self, key: Key) *Value {
return &self.values[Indexer.indexOf(key)];
}
/// Returns a const pointer to the slot in the array associated with a key.pubfngetPtrConst(self: *constSelf, key: Key) *constValue {
return &self.values[Indexer.indexOf(key)];
}
/// Sets the value in the slot associated with a key.pubfnset(self: *Self, key: Key, value: Value) void {
self.values[Indexer.indexOf(key)] = value;
}
/// Iterates over the items in the array, in index order.pubfniterator(self: *Self) Iterator {
return .{
.values = &self.values,
};
}
/// An entry in the array.pubconstEntry = struct {
/// The key associated with this entry./// Modifying this key will not change the array.key: Key,
/// A pointer to the value in the array associated/// with this key. Modifications through this/// pointer will modify the underlying data.value: *Value,
};
pubconstIterator = struct {
index: usize = 0,
values: *[Indexer.count]Value,
pubfnnext(self: *Iterator) ?Entry {
constindex = self.index;
if (index < Indexer.count) {
self.index += 1;
returnEntry{
.key = Indexer.keyForIndex(index),
.value = &self.values[index],
};
}
returnnull;
}
};
};
}
An array keyed by an enum, backed by a dense array. If the enum is not dense, a mapping will be constructed from enum values to dense indices. This type does no dynamic allocation and can be copied by value.