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.

Optimize

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

lang.Optimize
pub const Optimize = enum

File

lib/std/lang.zig:115

Code

pub const Optimize = enum {
    /// Safety checks enabled. Optimize for bug detection, accurate debug info,
    /// and compilation speed (in that order).
    debug,
    /// Safety checks enabled. Optimize for runtime performance.
    safe,
    /// Safety checks disabled. Optimize for runtime performance.
    fast,
    /// Safety checks disabled. Optimize for machine code size, then runtime performance.
    small,

    /// Deprecated, to be removed after 0.18.0
    pub const Debug: @This() = .debug;
    /// Deprecated, to be removed after 0.18.0
    pub const ReleaseSafe: @This() = .safe;
    /// Deprecated, to be removed after 0.18.0
    pub const ReleaseFast: @This() = .fast;
    /// Deprecated, to be removed after 0.18.0
    pub const ReleaseSmall: @This() = .small;
    /// Deprecated, to be removed after 0.18.0
    pub fn fromString(s: []const u8) ?@This() {
        return std.StaticStringMap(@This()).initComptime(&.{
            .{ "Debug", .debug },
            .{ "ReleaseSafe", .safe },
            .{ "ReleaseFast", .fast },
            .{ "ReleaseSmall", .small },
            .{ "debug", .debug },
            .{ "safe", .safe },
            .{ "fast", .fast },
            .{ "small", .small },
        }).get(s);
    }

    /// Returns whether illegal behavior safety checks are enabled based on the
    /// provided optimization mode.
    pub fn runtimeSafety(o: @This()) bool {
        return switch (o) {
            .debug, .safe => true,
            .fast, .small => false,
        };
    }
}