3 ms·
You can just used tagged enums and the inline else syntax, like this: const Animal = union(enum) { cat: Cat, dog: Dog, pub fn make_noise(s
by cgh 2y ago
You can just used tagged enums and the inline else syntax, like this:
const Animal = union(enum) {
cat: Cat,
dog: Dog,
pub fn make_noise(self: Animal) void {
switch (self) {
inline else => |impl| impl.make_noise(),
}
}
};
- 2c2c2c 2y agoiirc there's multiple idioms that are used in different cases. i recall a nice github that laid them all out with use cases but I can't find it