One method declaration; two Zig annoyances
Related
More from openmymind.net
If I asked you to respond to an HTTP request with a JSON serialize list of products, somewhere in your code, you'd probably have (or whatever the equivalent is in your stack): body, err := json.Marshal(products) There's an alternative to this approach that I'm rather fond of: gluing pre-serialized JSON pieces together: if (len(productJSON)) == 0...
A recently merged pull request removed anonymous struct from Zig. I was surprised by this change - it seemed like a big deal. But it turns out that I didn't understand what an anonymous struct were, and this change isn't quite as big as I thought. Consider this code: const std = @import("std"); pub fn main() !void { const user = .{.id = 2,...
In the last post, we looked at some of Zig' weirder syntax. Specifically, this line of code: var gpa = std.heap.GeneralPurposeAllocator(.{}){}; While you'll commonly run into the above when looking at Zig code or going through Zig learning resources, some people pointed out that the code could be improved by doing: var gpa:...
One of the first pieces of Zig code that you're likely to see, and write, is this beginner-unfriendly line: var gpa = std.heap.GeneralPurposeAllocator(.{}){}; While we can reason that we're creating an allocator, the (.{}){} syntax can seem a bit much. This is a combination of three separate language features: generics, anonymous struct literals...
Now that we're more familiar with epoll and kqueue individually, it's time to bring everything together. We'll begin by looking at the possible interaction between evented I/O and threads and then look at writing a basic cross-platform abstraction over the platform-specific epoll and kqueue. Evented I/O + Multithreading We began our journey with...