#Questions on naming conventions for types (and type-ish things)

1 messages · Page 1 of 1 (latest)

final coyote
#
const std = @import("std");
const Record = std.builtin.Type.Struct;

const MessageSpec = struct {
    header: ?type = void,
    kind: type,
    footer: ?type = void,
};

fn entry(comptime spec: MessageSpec) type {
    const header_val = spec.header orelse void;
    const footer_val = spec.footer orelse void;

    if (@typeInfo(spec.kind) != .@"enum") {
        @compileError("The value of .kind must be an enum.");
    }

    if (@typeInfo(header_val) == .void and @typeInfo(footer_val) == .void) {
        return struct {
            current_kind: spec.kind,
            next_kind: spec.kind,
        };
    } else if (@typeInfo(header_val) == .void) {
        return struct {
            current_kind: spec.kind,
            next_kind: spec.kind,
            footer: footer_val,
        };
    //..... removed due to word limitations
}

pub fn archive(comptime items: []const Record) type {
    if (!@typeInfo(@TypeOf(items)).@"struct") {
        @compileError("Archive must be initialized with an array of structs.");
    }
}
#

Questions on naming conventions for types (and typ-ish things)