#Function that can return one possible structure from two
1 messages · Page 1 of 1 (latest)
given
};
const B = struct {
};
you can do a function with this prototype
a: A,
b: B,
}```
where ! indicates the function can return anyerror and if it doesn't error, it will return a union of the two structs (think of it as it can return one of the fields of the union). If the parameter is comptime known you can do fancier
Parameter here is whatever type is your parameter
! doesn't indicate anyerror, it tries to infer the error set
sometimes the compiler can't infer the error and you have to explicitly tell it to except any error with anyerror!
oh yeah, sorry
See the return type of something like std.mem.asBytes.
You can write a type translation function and use it in the return type.
I need to figure some stuff out first as it seems. Maybe rethink the logic of my code, move some stuff here and there to make it work more nicely than it does now. Thanks for everyone's inputs.