We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suggested to me by mlugg', we could do either:
pub const Vec2 = struct { pub fn init(xs: u32, ys: u32) Vec2 { return .{ .v = .{ xs, ys } }; } const Shared = SharedImpl(@This()); pub const add = Shared.add; pub const sub = Shared.sub; }; pub const Vec3 = struct { pub fn init(xs: u32, ys: u32, zs: u32) Vec2 { return .{ .v = .{ xs, ys, zs } }; } const Shared = SharedImpl(@This()); pub const add = Shared.add; pub const sub = Shared.sub; }; fn SharedImpl(comptime T: type) type { return struct { fn add(a: *const T, b: *const T) T { return .{ .v = a.v + b.v }; } fn sub(a: *const T, b: *const T) T { return .{ .v = a.v - b.v }; } }; }
or new mixin strategy for more conventional mixin strategies:
pub const Vec2 = struct { v: @Vector(2, u32), shared: Shared(@This()), pub fn init(xs: u32, ys: u32) Vec2 { return .{ .v = .{ xs, ys } }; } }; pub const Vec3 = struct { v: @Vector(3, u32), shared: Shared(@This()), pub fn init(xs: u32, ys: u32, zs: u32) Vec2 { return .{ .v = .{ xs, ys, zs } }; } }; fn Shared(comptime T: type) type { return struct { fn add(a_shared: *const @This(), b: *const T) T { const a: *T = @fieldParentPtr("shared", a_shared); return .{ .v = a.v + b.v }; } fn sub(a_shared: *const @This(), b: *const T) T { const a: *T = @fieldParentPtr("shared", a_shared); return .{ .v = a.v - b.v }; } }; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
suggested to me by mlugg', we could do either:
or new mixin strategy for more conventional mixin strategies:
The text was updated successfully, but these errors were encountered: