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.

Package

Configuration.Package
pub const Package = struct

File

lib/std/Build/Configuration.zig:1592

Code

pub const Package = struct {
    dep_prefix: String,
    hash: String,
    root_path: String,

    pub const Index = enum(u32) {
        root = max_u32,
        _,

        /// Returns `null` for root package.
        pub fn get(i: @This(), c: *const Configuration) ?Package {
            if (i == .root) return null;
            return extraData(c, Package, @backingInt(i));
        }

        pub fn depPrefixSlice(i: @This(), c: *const Configuration) [:0]const u8 {
            const package = get(i, c) orelse return "";
            return package.dep_prefix.slice(c);
        }
    };

    pub const OptionalIndex = enum(u32) {
        none = max_u32 - 1,
        root = max_u32,
        _,

        pub fn init(i: Index) OptionalIndex {
            const result: OptionalIndex = @fromBackingInt(@intCast(@backingInt(i)));
            assert(result != .none);
            return result;
        }

        pub fn unwrap(this: @This()) ?Index {
            return switch (this) {
                .none => null,
                .root => .root,
                _ => @fromBackingInt(@intCast(@backingInt(this))),
            };
        }
    };
}