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 Struct

Capture

Public Struct
std.zig.Zir.Inst.Capture
pub const Capture = packed struct(u32)

Represents a single value being captured in a type declaration's closure.

Fields

tag: enum(u3) { /// `data` is a `u16` index into the parent closure. nested, /// `data` is a `Zir.Inst.Index` to an instruction whose value is being captured. instruction, /// `data` is a `Zir.Inst.Index` to an instruction representing an alloc whose contents is being captured. instruction_load, /// `data` is a `NullTerminatedString` to a decl name. decl_val, /// `data` is a `NullTerminatedString` to a decl name. decl_ref, }
data: u29

Types

Functions

pub fn wrap(cap: Unwrapped) Capture
pub fn unwrap(cap: Capture) Unwrapped

File

zig/Zir.zig:3536
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
    pub const Capture = packed struct(u32) {
        tag: enum(u3) {
            /// `data` is a `u16` index into the parent closure.
            nested,
            /// `data` is a `Zir.Inst.Index` to an instruction whose value is being captured.
            instruction,
            /// `data` is a `Zir.Inst.Index` to an instruction representing an alloc whose contents is being captured.
            instruction_load,
            /// `data` is a `NullTerminatedString` to a decl name.
            decl_val,
            /// `data` is a `NullTerminatedString` to a decl name.
            decl_ref,
        },
        data: u29,
        pub const Unwrapped = union(enum) {
            nested: u16,
            instruction: Zir.Inst.Index,
            instruction_load: Zir.Inst.Index,
            decl_val: NullTerminatedString,
            decl_ref: NullTerminatedString,
        };
        pub fn wrap(cap: Unwrapped) Capture {
            return switch (cap) {
                .nested => |idx| .{
                    .tag = .nested,
                    .data = idx,
                },
                .instruction => |inst| .{
                    .tag = .instruction,
                    .data = @intCast(@backingInt(inst)),
                },
                .instruction_load => |inst| .{
                    .tag = .instruction_load,
                    .data = @intCast(@backingInt(inst)),
                },
                .decl_val => |str| .{
                    .tag = .decl_val,
                    .data = @intCast(@backingInt(str)),
                },
                .decl_ref => |str| .{
                    .tag = .decl_ref,
                    .data = @intCast(@backingInt(str)),
                },
            };
        }
        pub fn unwrap(cap: Capture) Unwrapped {
            return switch (cap.tag) {
                .nested => .{ .nested = @intCast(cap.data) },
                .instruction => .{ .instruction = @fromBackingInt(@intCast(cap.data)) },
                .instruction_load => .{ .instruction_load = @fromBackingInt(@intCast(cap.data)) },
                .decl_val => .{ .decl_val = @fromBackingInt(@intCast(cap.data)) },
                .decl_ref => .{ .decl_ref = @fromBackingInt(@intCast(cap.data)) },
            };
        }
    }