// Déclaration d'une struct avec une fonction (ce qui ressemble le // plus, en Zig, à de la programmation objet. const std = @import("std"); pub fn main() void { const Point = struct { x: usize, y: usize, // Pour formater joliment lors de l'impression https://ziglang.org/documentation/master/std/#std.fmt pub fn format(value: @This(), comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { return writer.print("[{d}, {d}]", .{ value.x, value.y }); } pub fn eql(self: @This(), other: @This()) bool { return self.x == other.x and self.y == other.y; } }; const origin = Point{ .x = 0, .y = 0 }; const uninitialized: Point = undefined; const somewhere = Point{ .x = 3, .y = 5 }; std.debug.print("{any} == {any} ? : {any}\n", .{ origin, uninitialized, origin.eql(uninitialized) }); std.debug.print("{any} == {any} ? : {any}\n", .{ origin, somewhere, origin.eql(somewhere) }); }