by rto_victim · 1y ago · 0 comments
Ideally we'd have unions which gets rid of the bike shedding that comes with sums [1].
(Zig is similar but doesn't support different types of payloads on the different error values).
In your case you can either model it with a sum type or wrap each variant in its own type and take the union of them.
Example:
enum Result {
Success(String),
Error(String),
}
struct Success(String);
struct Error(String);
type Result = Success | Error;