Now that #1047 is done, and every file is implicitly an empty struct, we could allow fields at the top level. This would solve the redundant import problem:
https://github.com/ziglang/zig/blob/96164ce61377b36bcaf0c4087ca9b1ab822b9457/std/index.zig#L3-L10
Syntactically it looks a bit odd, but semantically it makes sense.
This seems to already work in stage 1:
a: u8,
test "" {
var s = @This(){ .a = 22 };
@import("std").testing.expectEqual(u8(22), s.a);
}
When I did the grammar rework I allowed fields at top level in the syntax, and now that files are empty structs, it seems to work it just haven't been tested. To close this, we probably need:
std refactorah! I got tricked by vim integration with zig fmt :laughing:
Also just to repeat this here:
The "index.zig" convention is deprecated. The new pattern is the one set by
Also, files cannot be generic so the redundant import problem is only solved for none generic structs.
I was in the mood for a little bit of bikeshedding, so I refactored my project to use toplevel fields wherever possible. No issues so far on zig 0.6.0. Repository here for the curious: https://github.com/ifreund/river.
Most helpful comment
I was in the mood for a little bit of bikeshedding, so I refactored my project to use toplevel fields wherever possible. No issues so far on zig 0.6.0. Repository here for the curious: https://github.com/ifreund/river.