Skip to content

Commit

Permalink
Fix compile on zig 0.12.0-dev.1828+225fe6ddb (#2)
Browse files Browse the repository at this point in the history
Zig now requires variables that are not being mutated to be declared as const
  • Loading branch information
Cloudef authored Dec 22, 2023
1 parent dbfad24 commit 40e80d5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ulid.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub const Ulid = packed struct {
}

pub fn encodeAlloc(self: @This(), allocator: std.mem.Allocator) ![]u8 {
var out = try allocator.alloc(u8, text_length);
const out = try allocator.alloc(u8, text_length);
self.encodeBuf(out) catch unreachable;
return out;
}
Expand Down Expand Up @@ -164,7 +164,7 @@ pub const Factory = struct {
};

export fn ulid_factory() ?*anyopaque {
var factory = std.heap.c_allocator.create(Factory) catch {
const factory = std.heap.c_allocator.create(Factory) catch {
return null;
};
factory.* = Factory{};
Expand Down Expand Up @@ -221,11 +221,11 @@ export fn ulid_timestamp_ms(ulid: UlidC) i64 {
}

test "c" {
var factory = ulid_factory().?;
const factory = ulid_factory().?;
const id0 = ulid_next(factory);
var buf = try std.testing.allocator.alloc(u8, text_length);
const buf = try std.testing.allocator.alloc(u8, text_length);
defer std.testing.allocator.free(buf);
var buf_ptr: [*]u8 = @ptrCast(buf);
const buf_ptr: [*]u8 = @ptrCast(buf);
ulid_encode(id0, buf_ptr);
try std.testing.expectEqual(ulid_decode(buf_ptr), id0);
}
Expand Down

0 comments on commit 40e80d5

Please sign in to comment.