Skip to content

Commit b3a83c3

Browse files
committed
feat: support zig 0.14.0
Close: #5
1 parent 4eed6cc commit b3a83c3

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

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.13.0**
9+
**NOTE: Supported Zig Version is 0.14.0**
1010

1111
## What is `struct-env`
1212

build.zig.zon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.{
2-
.name = "struct-env",
3-
.version = "0.3.0",
2+
.name = .struct_env,
3+
.fingerprint=0x1ec612b14680944c,
4+
.version = "0.4.0",
45
.dependencies = .{},
56
.paths = .{""},
67
}

src/lib.zig

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub const StructEnv = struct {
109109
/// Get the default value of a struct field, return null if there is no default value.
110110
fn getDefault(self: Self, comptime T: type, comptime field: Field) ?T {
111111
_ = self;
112-
if (field.default_value) |default_value| {
112+
if (field.default_value_ptr) |default_value| {
113113
const anyopaque_pointer: *anyopaque = @constCast(default_value);
114114
return @as(*T, @ptrCast(@alignCast(anyopaque_pointer))).*;
115115
}
@@ -120,24 +120,24 @@ pub const StructEnv = struct {
120120
/// Deserialize into a value
121121
fn deserializeInto(self: *Self, ptr: anytype, comptime field: ?Field) !void {
122122
const T = @TypeOf(ptr);
123-
comptime assert(is(.Pointer)(T));
123+
comptime assert(is(.pointer)(T));
124124

125125
const C = comptime meta.Child(T);
126126

127127
ptr.* = switch (C) {
128128
[]const u8 => try self.deserializeString(C, field.?),
129129
// ?[]const u8 => null,
130130
else => switch (@typeInfo(C)) {
131-
.Struct => try self.deserializeStruct(C),
132-
.Enum => try self.deserializeEnum(C, field.?),
133-
.Optional => try self.deserializeOptional(C, field.?),
134-
.Bool => try self.deserializeBool(C, field.?),
131+
.@"struct" => try self.deserializeStruct(C),
132+
.@"enum" => try self.deserializeEnum(C, field.?),
133+
.optional => try self.deserializeOptional(C, field.?),
134+
.bool => try self.deserializeBool(C, field.?),
135135
// .Int => |info| info.bits,
136-
.Int => try self.deserializeInt(C, field.?),
137-
.Float => try self.deserializeFloat(C, field.?),
136+
.int => try self.deserializeInt(C, field.?),
137+
.float => try self.deserializeFloat(C, field.?),
138138
// .Array => try self.deserializeArray(C),
139139
// .Vector => try self.deserializeVector(C),
140-
.Pointer => try self.deserializePointer(C, field.?),
140+
.pointer => try self.deserializePointer(C, field.?),
141141

142142
// ...
143143
else => @compileError("Unsupported deserialization type " ++ @typeName(C) ++ "\n"),
@@ -195,7 +195,7 @@ pub const StructEnv = struct {
195195
if (value) |v| {
196196
const C = comptime meta.Child(T);
197197
// TODO: delimiter
198-
var it = std.mem.split(u8, v, ",");
198+
var it = std.mem.splitSequence(u8, v, ",");
199199
var new_value = std.ArrayList(C).init(self.allocator);
200200
defer new_value.deinit();
201201

@@ -204,9 +204,9 @@ pub const StructEnv = struct {
204204
[]const u8 => try self.allocator.dupe(u8, s),
205205
// []const u8 => s,
206206
else => switch (@typeInfo(C)) {
207-
.Bool => try utils.str2bool(self.allocator, s),
208-
.Int => try std.fmt.parseInt(C, s, 0),
209-
.Float => try std.fmt.parseFloat(C, s, 0),
207+
.bool => try utils.str2bool(self.allocator, s),
208+
.int => try std.fmt.parseInt(C, s, 0),
209+
.float => try std.fmt.parseFloat(C, s, 0),
210210
else => @compileError("Unsupported deserialization type" ++ @typeName(C) ++ "\n"),
211211
},
212212
};
@@ -226,9 +226,9 @@ pub const StructEnv = struct {
226226
const item = switch (C) {
227227
[]const u8 => try self.allocator.dupe(u8, s),
228228
else => switch (@typeInfo(C)) {
229-
.Bool => s,
230-
.Int => s,
231-
.Float => s,
229+
.bool => s,
230+
.int => s,
231+
.float => s,
232232
else => @compileError("Unsupported deserialization type" ++ @typeName(C) ++ "\n"),
233233
},
234234
};
@@ -322,7 +322,7 @@ pub fn free(allocator: std.mem.Allocator, value: anytype) void {
322322
[]const u8 => allocator.free(@field(value, struct_field.name)),
323323
else => {
324324
switch (@typeInfo(struct_field.type)) {
325-
.Pointer => {
325+
.pointer => {
326326
const need_free = true;
327327
// const cur = @field(value, struct_field.name);
328328

0 commit comments

Comments
 (0)