foxwhale
foxwhale copied to clipboard
Proposal: Typed containers
Problem
At the moment an Object
has a container
field of type usize
that stores a pointer to one of the compositor's structures. We use @intToPtr
to get a pointer to said structure. Obviously this lacks type safety.
Proposal
Using the comptime features of zig, we could at compile time, parameterise the Object
with parameter T
. We set container
to be of type T
or a pointer to type T
then anywhere in the code that references Object
would instead reference Object(Container)
if we defined Container
to be a tagged union of pointers to different types of containers.
Benefits
- Type safety
Thoughts
- If the
wl
directory is ever spun out as a library, this would become a source-only library (no dynamic linking). I'm totally fine with that, I'd rather it not be dynamically linked.
Also, we should really store the index / handle of the container rather than a pointer as pointers are potentially invalidated on realloc (though we're not realloc'ing a the moment). See https://github.com/malcolmstill/foxwhale/issues/44