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.

OptimizationLevel

CodeGenOptions.OptimizationLevel
pub const OptimizationLevel = enum

File

lib/compiler/aro/backend/CodeGenOptions.zig:41

Code

pub const OptimizationLevel = enum {
    @"0",
    @"1",
    @"2",
    @"3",
    /// Optimize for size
    s,
    /// Disregard strict standards compliance
    fast,
    /// Optimize debugging experience
    g,
    /// Optimize aggressively for size rather than speed
    z,

    const level_map = std.StaticStringMap(OptimizationLevel).initComptime(.{
        .{ "0", .@"0" },
        .{ "1", .@"1" },
        .{ "2", .@"2" },
        .{ "3", .@"3" },
        .{ "s", .s },
        .{ "fast", .fast },
        .{ "g", .g },
        .{ "z", .z },
    });

    pub fn fromString(str: []const u8) ?OptimizationLevel {
        return level_map.get(str);
    }

    pub fn isSizeOptimized(self: OptimizationLevel) bool {
        return switch (self) {
            .s, .z => true,
            .@"0", .@"1", .@"2", .@"3", .fast, .g => false,
        };
    }

    pub fn hasAnyOptimizations(self: OptimizationLevel) bool {
        return switch (self) {
            .@"0" => false,
            .@"1", .@"2", .@"3", .s, .fast, .g, .z => true,
        };
    }
}