|
|
|
|
|
by Zambyte
403 days ago
|
|
I have been using Zig a lot lately, and I just want to share the equivalent of the let-else solution in Zig: const user = getUser() orelse return error.NoUser;
If you only need user for a narrow scope like you would get from match, you can also use if to unwrap the optional. if (getUser()) |user| {
// use user
} else {
return error.NoUser;
}
|
|