Skip to content

Commit 303a130

Browse files
authored
feat: support zig 0.15.1 (#7)
1 parent fdb2e63 commit 303a130

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
name: Tests on Linux
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v3
16-
- uses: goto-bus-stop/setup-zig@v2
15+
- uses: actions/checkout@v4
16+
- uses: mlugg/setup-zig@v2
1717
with:
18-
version: 0.14.0
18+
version: 0.15.1
1919
- run: zig version
2020
- run: zig env
2121
- name: Build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![codecov](https://codecov.io/gh/Hanaasagi/struct-env/branch/master/graph/badge.svg?token=DQQZETSCW3)](https://codecov.io/gh/Hanaasagi/struct-env)
77
![](https://img.shields.io/badge/language-zig-%23ec915c)
88

9-
**NOTE: Supported Zig Version is 0.14.0**
9+
**NOTE: Supported Zig Version is 0.15.1**
1010

1111
## What is `struct-env`
1212

build.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ pub fn build(b: *std.Build) void {
4444
// Creates a step for unit testing. This only builds the test executable
4545
// but does not run it.
4646
const lib_tests = b.addTest(.{
47-
.root_source_file = b.path("src/lib.zig"),
48-
.target = target,
49-
.optimize = optimize,
47+
.root_module = b.createModule(.{
48+
.root_source_file = b.path("src/lib.zig"),
49+
.target = target,
50+
.optimize = optimize,
51+
}),
5052
});
5153

5254
const run_lib_tests = b.addRunArtifact(lib_tests);

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = .struct_env,
33
.fingerprint=0x1ec612b14680944c,
4-
.version = "0.4.0",
4+
.version = "0.4.1",
55
.dependencies = .{},
66
.paths = .{""},
77
}

src/lib.zig

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ const utils = @import("./utils.zig");
55
const Field = std.builtin.Type.StructField;
66
const testing = std.testing;
77

8-
// See https://github.com/ziglang/zig/pull/18061
9-
pub const TraitFn = fn (type) callconv(.Inline) bool;
8+
pub const TraitFn = fn (type) bool;
109
pub fn is(comptime id: std.builtin.TypeId) TraitFn {
1110
const Closure = struct {
12-
pub inline fn trait(comptime T: type) bool {
11+
pub fn trait(comptime T: type) bool {
1312
return id == @typeInfo(T);
1413
}
1514
};
@@ -196,8 +195,8 @@ pub const StructEnv = struct {
196195
const C = comptime meta.Child(T);
197196
// TODO: delimiter
198197
var it = std.mem.splitSequence(u8, v, ",");
199-
var new_value = std.ArrayList(C).init(self.allocator);
200-
defer new_value.deinit();
198+
var new_value = std.ArrayList(C){};
199+
defer new_value.deinit(self.allocator);
201200

202201
while (it.next()) |s| {
203202
const item = switch (C) {
@@ -210,17 +209,17 @@ pub const StructEnv = struct {
210209
else => @compileError("Unsupported deserialization type" ++ @typeName(C) ++ "\n"),
211210
},
212211
};
213-
try new_value.append(item);
212+
try new_value.append(self.allocator, item);
214213
}
215214

216-
return new_value.toOwnedSlice();
215+
return try new_value.toOwnedSlice(self.allocator);
217216
}
218217

219218
const default_value = self.getDefault(T, field);
220219
if (default_value) |v| {
221220
const C = comptime meta.Child(T);
222-
var new_value = std.ArrayList(C).init(self.allocator);
223-
defer new_value.deinit();
221+
var new_value = std.ArrayList(C){};
222+
defer new_value.deinit(self.allocator);
224223

225224
for (v) |s| {
226225
const item = switch (C) {
@@ -232,10 +231,10 @@ pub const StructEnv = struct {
232231
else => @compileError("Unsupported deserialization type" ++ @typeName(C) ++ "\n"),
233232
},
234233
};
235-
try new_value.append(item);
234+
try new_value.append(self.allocator, item);
236235
}
237236

238-
return new_value.toOwnedSlice();
237+
return try new_value.toOwnedSlice(self.allocator);
239238
}
240239

241240
return Error.NotExist;

0 commit comments

Comments
 (0)