Skip to content

Instantly share code, notes, and snippets.

@marler8997
Created April 18, 2021 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marler8997/64338f902027783d2159abbaf796b6a6 to your computer and use it in GitHub Desktop.
Save marler8997/64338f902027783d2159abbaf796b6a6 to your computer and use it in GitHub Desktop.
Zig Copy Semantics
const std = @import("std");
test {
const U = union(enum) {
Val: isize,
Point: struct { x: isize, y: isize },
};
var u = U { .Point = .{ .x = 123, .y = 456 } };
const p = &u.Point;
u = U { .Val = p.x + p.y };
std.testing.expect(u.Val == 579);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment