Discussion: Upcoming @backingInt() and @fromBackingInt() convenience builtins

I just saw these in the master branch standard library and documentation:

They seem to use a new standard library construct: std.meta.BackingInt()

Here’s an example of a function where they’re already being used: std.log.logEnabled()

While this is nothing that couldn’t have been implemented in userland with some imaginative use of switch(@typeInfo(@TypeOf(arg))), it’s exciting to see new convenience builtins, which will surely be cited in the release notes as “part of the ongoing effort to improve ergonomics for game development”.

I bet a lot more people will be more willing to play around with packed structs and enums with these new builtins in place, particularly stuff like non-exhaustive enums as indices for concepts like Data-Oriented Design.

7 Likes

I already had opportunity to use it.
https://codeberg.org/andrewkraevskii/steam_train/src/commit/e0248bee3cbfce75d25da73f28c1228acf160195/src/wasm4.zig#L62
Previously it would have been written as @as(u32, @bitcast(self))

3 Likes

Having dabbled in embedded Zig recently, this will be a very welcome addition!

1 Like