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. Private Function

constructInput

Private Function
std.testing.Smith.constructInput
fn constructInput(comptime values: []const union(enum)

Params

  • values: []const union(enum) { eos: bool, int: u64, bytes: []const u8, slice: []const u8, }

File

testing/Smith.zig:674
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
fn constructInput(comptime values: []const union(enum) {
    eos: bool,
    int: u64,
    bytes: []const u8,
    slice: []const u8,
}) []const u8 {
    const result = comptime result: {
        var result: [
            len: {
                var len = 0;
                for (values) |v| len += switch (v) {
                    .eos => 1,
                    .int => 8,
                    .bytes => |b| b.len,
                    .slice => |s| 4 + s.len,
                };
                break :len len;
            }
        ]u8 = undefined;
        var w: std.Io.Writer = .fixed(&result);

        for (values) |v| switch (v) {
            .eos => |e| w.writeByte(@intFromBool(e)) catch unreachable,
            .int => |i| w.writeInt(u64, i, .little) catch unreachable,
            .bytes => |b| w.writeAll(b) catch unreachable,
            .slice => |s| {
                w.writeInt(u32, @intCast(s.len), .little) catch unreachable;
                w.writeAll(s) catch unreachable;
            },
        };

        break :result result;
    };
    return &result;
}