In src/build/specialize_types/IR.zig it's very common to see a List
, Slice
, NonEmptySlice
,... inside the struct. Is this a zig convention?
/// A definition, e.g. `x = foo`
pub const Def = struct {
pattern: Pattern.Idx,
/// Named variables in the pattern, e.g. `a` in `Ok a ->`
pattern_vars: TypedIdent.Slice,
expr: Expr.Idx,
expr_type: Type.Idx,
/// todo
pub const List = collections.SafeMultiList(@This());
/// todo
pub const Slice = List.Slice;
};
Yeah, it's for type safety and ease of use. I have definitely seen it in other zig code. Especially common for DOD types that will only ever be in lists. It's the basic way to make associated types
Last updated: Jul 06 2025 at 12:14 UTC