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.EnumSet.Self
pubfnEnumSet(comptimeE: type) type
A set of enum elements, backed by a bitfield. If the enum is exhaustive but 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.
pubfnEnumSet(comptimeE: type) type {
returnstruct {
constSelf = @This();
/// The indexing rules for converting between keys and indices.pubconstIndexer = EnumIndexer(E);
/// The element type for this set.pubconstKey = Indexer.Key;
constBitSet = std.bit_set.Static(Indexer.count);
/// The maximum number of items in this set.pubconstlen = Indexer.count;
bits: BitSet = .empty,
/// Initializes the set using a struct of boolspubfninit(init_values: EnumFieldStruct(E, bool, false)) Self {
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
varresult: Self = .{};
if (@typeInfo(E).@"enum".mode == .exhaustive) {
inlinefor (0..Self.len) |i| {
constkey = comptimeIndexer.keyForIndex(i);
consttag = @tagName(key);
if (@field(init_values, tag)) {
result.bits.set(i);
}
}
} else {
inlinefor (@typeInfo(E).@"enum".field_names) |field_name| {
constkey = @field(E, field_name);
if (@field(init_values, field_name)) {
consti = comptimeIndexer.indexOf(key);
result.bits.set(i);
}
}
}
returnresult;
}
/// A set containing no keys.pubconstempty: Self = .{ .bits = .empty };
/// A set containing all possible keys.pubconstfull: Self = .{ .bits = .full };
/// Returns a set containing multiple keys.pubfninitMany(keys: []constKey) Self {
varset: Self = .empty;
for (keys) |key| set.insert(key);
returnset;
}
/// Returns a set containing a single key.pubfninitOne(key: Key) Self {
returninitMany(&[_]Key{key});
}
/// Returns the number of keys in the set.pubfncount(self: Self) usize {
returnself.bits.count();
}
/// Checks if a key is in the set.pubfncontains(self: Self, key: Key) bool {
returnself.bits.isSet(Indexer.indexOf(key));
}
/// Puts a key in the set.pubfninsert(self: *Self, key: Key) void {
self.bits.set(Indexer.indexOf(key));
}
/// Removes a key from the set.pubfnremove(self: *Self, key: Key) void {
self.bits.unset(Indexer.indexOf(key));
}
/// Changes the presence of a key in the set to match the passed bool.pubfnsetPresent(self: *Self, key: Key, present: bool) void {
self.bits.setValue(Indexer.indexOf(key), present);
}
/// Toggles the presence of a key in the set. If the key is in/// the set, removes it. Otherwise adds it.pubfntoggle(self: *Self, key: Key) void {
self.bits.toggle(Indexer.indexOf(key));
}
/// Toggles the presence of all keys in the passed set.pubfntoggleSet(self: *Self, other: Self) void {
self.bits.toggleSet(other.bits);
}
/// Toggles all possible keys in the set.pubfntoggleAll(self: *Self) void {
self.bits.toggleAll();
}
/// Adds all keys in the passed set to this set.pubfnsetUnion(self: *Self, other: Self) void {
self.bits.setUnion(other.bits);
}
/// Removes all keys which are not in the passed set.pubfnsetIntersection(self: *Self, other: Self) void {
self.bits.setIntersection(other.bits);
}
/// Returns true iff both sets have the same keys.pubfneql(self: Self, other: Self) bool {
returnself.bits.eql(other.bits);
}
/// Returns true iff all the keys in this set are/// in the other set. The other set may have keys/// not found in this set.pubfnsubsetOf(self: Self, other: Self) bool {
returnself.bits.subsetOf(other.bits);
}
/// Returns true iff this set contains all the keys/// in the other set. This set may have keys not/// found in the other set.pubfnsupersetOf(self: Self, other: Self) bool {
returnself.bits.supersetOf(other.bits);
}
/// Returns a set with all the keys not in this set.pubfncomplement(self: Self) Self {
return .{ .bits = self.bits.complement() };
}
/// Returns a set with keys that are in either this/// set or the other set.pubfnunionWith(self: Self, other: Self) Self {
return .{ .bits = self.bits.unionWith(other.bits) };
}
/// Returns a set with keys that are in both this/// set and the other set.pubfnintersectWith(self: Self, other: Self) Self {
return .{ .bits = self.bits.intersectWith(other.bits) };
}
/// Returns a set with keys that are in either this/// set or the other set, but not both.pubfnxorWith(self: Self, other: Self) Self {
return .{ .bits = self.bits.xorWith(other.bits) };
}
/// Returns a set with keys that are in this set/// except for keys in the other set.pubfndifferenceWith(self: Self, other: Self) Self {
return .{ .bits = self.bits.differenceWith(other.bits) };
}
/// Returns an iterator over this set, which iterates in/// index order. Modifications to the set during iteration/// may or may not be observed by the iterator, but will/// not invalidate it.pubfniterator(self: *constSelf) Iterator {
return .{ .inner = self.bits.iterator(.{}) };
}
pubconstIterator = struct {
inner: BitSet.Iterator(.{}),
pubfnnext(self: *Iterator) ?Key {
returnif (self.inner.next()) |index|
Indexer.keyForIndex(index)
elsenull;
}
};
};
}
A set of enum elements, backed by a bitfield. If the enum is exhaustive but 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.