We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
std.meta.eql
==
packed struct
1 parent c894ac0 commit b2030cbCopy full SHA for b2030cb
lib/std/meta.zig
@@ -737,13 +737,15 @@ test TagPayload {
737
try testing.expect(MovedEvent == @TypeOf(e.Moved));
738
}
739
740
-/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
741
-/// where possible. Pointers are not followed.
+/// Compares two of any type for equality. Containers that do not support comparison
+/// on their own are compared on a field-by-field basis. Pointers are not followed.
742
pub fn eql(a: anytype, b: @TypeOf(a)) bool {
743
const T = @TypeOf(a);
744
745
switch (@typeInfo(T)) {
746
.@"struct" => |info| {
747
+ if (info.layout == .@"packed") return a == b;
748
+
749
inline for (info.fields) |field_info| {
750
if (!eql(@field(a, field_info.name), @field(b, field_info.name))) return false;
751
0 commit comments