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.

getByIdentifier

code_pages.getByIdentifier
pub fn getByIdentifier(identifier: u16) !CodePage

File

lib/compiler/resinator/code_pages.zig:201

Code

pub fn getByIdentifier(identifier: u16) !CodePage {
    // There's probably a more efficient way to do this (e.g. ComptimeHashMap?) but
    // this should be fine, especially since this function likely won't be called much.
    const info = @typeInfo(CodePage).@"enum";
    inline for (info.field_names, info.field_values) |field_name, field_value| {
        if (identifier == field_value) {
            return @field(CodePage, field_name);
        }
    }
    return error.InvalidCodePage;
}