Skip to content

Instantly share code, notes, and snippets.

@haze
Created May 29, 2021 17:50
Show Gist options
  • Save haze/9fbc2728f5c7623b70d829abafc6375f to your computer and use it in GitHub Desktop.
Save haze/9fbc2728f5c7623b70d829abafc6375f to your computer and use it in GitHub Desktop.
pub fn main() anyerror!void {
@import("std").log.info("x={}", .{try foo(23)});
}
fn foo(x: usize) !?Union {
if (x > 5) return Union.x;
return bar();
}
fn bar() !?Union {
return null;
}
const Enum = enum { x, y, z };
const Union = union(Enum) { x, y, z };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment