Zig 0.17.0-dev (Split by item)

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 library itself.

AwaitableId

A sequence of (ptr_bit_width - 3) bits which uniquely identifies a group or future. The bits are the MSBs of the *Io.Group or *Future. These things do not necessarily have 3 zero bits at the end (they are pointer-aligned, so on 32-bit targets only have 2), but because they both have a size of at least 8 bytes, no two groups/futures in memory at the same time will have the same value for all of these bits. In other words, given a group/future pointer, the next group or future must be at least 8 bytes later, so its address will have a different value for one of the top (ptr_bit_width - 3) bits.

Threaded.AwaitableId
const AwaitableId = enum(@Int(.unsigned, @bitSizeOf(usize) - 3))

File

lib/std/Io/Threaded.zig:801

Code

const AwaitableId = enum(@Int(.unsigned, @bitSizeOf(usize) - 3)) {
    comptime {
        assert(@sizeOf(Future) >= 8);
        assert(@sizeOf(Io.Group) >= 8);
    }
    null = 0,
    all_ones = std.math.maxInt(@Int(.unsigned, @bitSizeOf(usize) - 3)),
    _,
    const Split = packed struct(usize) { low: u3, high: AwaitableId };
    fn fromGroup(g: *Io.Group) AwaitableId {
        const split: Split = @bitCast(@intFromPtr(g));
        return split.high;
    }
    fn fromFuture(f: *Future) AwaitableId {
        const split: Split = @bitCast(@intFromPtr(f));
        return split.high;
    }
}