Hi, I’m very new to Zig, coming from Rust, and basically just finished ziglings after a few weekends. Now I want to create my first little project. It is supposed to be a simple server that manages a list of “work”/“resources” that is distributed to clients. A client requests a resource, does some work, and then confirms it did the work, then the server marks it as done. I am having a bit of trouble with the general setup. My idea was to structure it like this:
const Resource = struct {
work: []u8,
};
// got this idea from https://matklad.github.io/2025/12/23/zig-newtype-index-pattern.html
const ResourceId = enum(u32) {
_,
};
/// container for resources
const Pool = struct {
name: []const u8,
resources: std.HashMap(todo); // all resources, map of ResourceId->Resource
// lists of IDs to keep the resource states, trying to be data-oriented or something
free_resources: std.ArrayList(ResourceId),
pending_resources: std.ArrayList(ResourceId),
done_resources: std.ArrayList(ResourceId),
};
The “work” is just a string (maybe json, idk yet) that the client will receive.
- Resource is supposed to own the
workstring/data. Is it right to use a u8 slice for this case? Because my understanding of a slice is that it can point to any part of e.g. a string. How would I be sure that the resource instance owns this? E.g. when I free a Resource instance, I could not safely free the slice, because it could have been created from anything. - For something like a Pool which should be dynamically allocated, is there a convention for naming a “constructor” method (e.g.
init)? Is it even normal to have such a method? I think you would have to pass it an allocator, right? - My whole approach feels a bit weird, perhaps because I cannot see the bigger picture due to missing experience.
These are really just the first few lines I wrote and I already have a lot of questions
.. For me it is definitely harder than Rust, but maybe it is just beginner’s paralysis.. Thank you for any help!!