Meta type ‣ isFieldTypedArray(T, name) - chung-leong/zigar GitHub Wiki

Determine whether a struct/union field should be a typed array.

Usage:

const std = @import("std");

const Struct = struct {
    field: []const u8 = "hello",
};
pub const structure: Struct = .{};

const module = @This();
pub const @"meta(zigar)" = struct {
    pub fn isFieldTypedArray(comptime T: type, comptime name: std.meta.FieldEnum(T)) bool {
        return T == Struct and name == .field;
    }
};
import { structure } from './meta-type-typed-array-example-2.zig';

console.log(structure.field);
Uint8Array(5) [ 104, 101, 108, 108, 111 ]

Arguments:

  • T - Struct/union type in question
  • name - Name of the field represented by an enum

Meta types | Typed array