Where is the std.meta.trait package in Zig 0.12

Hi, I try to update my zig Project from version 0.11 to 0.12 and realize that the package std.meta.trait is gone in 0.12 and I can’t find it anywhere else.

I use trait functions in my code, how can I adapt them to new API?

Thanks for any help.

Workaround: copied the older std.meta.trait.zig from version 0.11 into my project and works, only hat to convert some var to const.

A better solution might be to delete all the std.meta.trait calls, or replace them with assert or @compileError calls.

I use them to check if certain declarations are available for a type within generic function and if so, invoke them when needed like this:

comptime var has_destruct = trait.hasDecls(T, .{"destruct"});
fn dispose(index: usize)  void {
    var t: T = removeAt(index);
    if (has_destruct ) {

Currently I see no way to simple replace them with assets or @compileError, do you?

You can use @hasDecl:

const has_destruct = @hasDecl(T, "destruct");

Yes this works and also @hasField exists, didn’t know about this built-ins, thanks!

1 Like

To answer the original question: