Swap order of EntityPart.id and .name

main
copygirl 1 year ago
parent 8d0edc12f3
commit bd51b09ad6
  1. 10
      src/path.zig

@ -23,8 +23,8 @@ pub const Path = struct {
/// Represents an `Entity` in a `Path`, either by name or its numeric id. /// Represents an `Entity` in a `Path`, either by name or its numeric id.
pub const EntityPart = union(enum) { pub const EntityPart = union(enum) {
name: []const u8,
id: u32, id: u32,
name: []const u8,
}; };
/// Format used to parse and stringify `Path`s. /// Format used to parse and stringify `Path`s.
@ -265,8 +265,8 @@ pub const Path = struct {
if (first.absolute != second.absolute) return false; if (first.absolute != second.absolute) return false;
if (first.parts.len != second.parts.len) return false; if (first.parts.len != second.parts.len) return false;
for (first.parts, second.parts) |a, b| switch (a) { for (first.parts, second.parts) |a, b| switch (a) {
.name => |a_name| if (b != .name or !std.mem.eql(u8, a_name, b.name)) return false,
.id => |a_id| if (b != .id or a_id != b.id) return false, .id => |a_id| if (b != .id or a_id != b.id) return false,
.name => |a_name| if (b != .name or !std.mem.eql(u8, a_name, b.name)) return false,
}; };
return true; return true;
} }
@ -282,8 +282,8 @@ pub const Path = struct {
// Parts themselves. // Parts themselves.
for (self.parts) |part| for (self.parts) |part|
result += switch (part) { result += switch (part) {
.name => |name| name.len,
.id => |id| numDigits(id), .id => |id| numDigits(id),
.name => |name| name.len,
}; };
return result; return result;
} }
@ -296,15 +296,15 @@ pub const Path = struct {
} }
// Write the first part. // Write the first part.
switch (self.parts[0]) { switch (self.parts[0]) {
.name => |name| try writer.writeAll(name),
.id => |id| try writer.writeIntNative(u32, id), .id => |id| try writer.writeIntNative(u32, id),
.name => |name| try writer.writeAll(name),
} }
// Write the remaining parts, each preceeded bu separator. // Write the remaining parts, each preceeded bu separator.
for (self.parts[1..]) |part| { for (self.parts[1..]) |part| {
try writer.writeAll(opt.sep); try writer.writeAll(opt.sep);
switch (part) { switch (part) {
.name => |name| try writer.writeAll(name),
.id => |id| try writer.writeIntNative(u32, id), .id => |id| try writer.writeIntNative(u32, id),
.name => |name| try writer.writeAll(name),
} }
} }
} }

Loading…
Cancel
Save