Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ jobs:
- uses: actions/checkout@v3
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0
version: 0.14.0
- run: zig version
- run: zig env
- name: Build
run: zig build --verbose
- name: Run Tests
run: zig build test
- name: Install kcov
run: sudo apt-get install -y kcov
- name: Generate coverage
run: kcov $PWD/kcov-out ./.zig-cache/o/*/test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./kcov-out/test
verbose: true
fail_ci_if_error: true
# - name: Install kcov
# run: sudo apt-get install -y kcov
# - name: Generate coverage
# run: kcov $PWD/kcov-out ./.zig-cache/o/*/test
# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v5
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# directory: ./kcov-out/test
# verbose: true
# fail_ci_if_error: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![codecov](https://codecov.io/gh/Hanaasagi/struct-env/branch/master/graph/badge.svg?token=DQQZETSCW3)](https://codecov.io/gh/Hanaasagi/struct-env)
![](https://img.shields.io/badge/language-zig-%23ec915c)

**NOTE: Supported Zig Version is 0.13.0**
**NOTE: Supported Zig Version is 0.14.0**

## What is `struct-env`

Expand Down
5 changes: 3 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.{
.name = "struct-env",
.version = "0.3.0",
.name = .struct_env,
.fingerprint=0x1ec612b14680944c,
.version = "0.4.0",
.dependencies = .{},
.paths = .{""},
}
8 changes: 4 additions & 4 deletions examples/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const examples = .{
"prefix",
};

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

Expand All @@ -21,14 +21,14 @@ pub fn build(b: *std.build.Builder) void {

const exe = b.addExecutable(.{
.name = exe_name,
.root_source_file = .{ .path = example_path },
.root_source_file = b.path(example_path),
.target = target,
.optimize = optimize,
});
const mod = b.addModule("struct-env", .{
.source_file = .{ .path = "../src/lib.zig" },
.root_source_file = b.path("../src/lib.zig"),
});
exe.addModule("struct-env", mod);
exe.root_module.addImport("struct-env", mod);

b.installArtifact(exe);

Expand Down
34 changes: 17 additions & 17 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub const StructEnv = struct {
/// Get the default value of a struct field, return null if there is no default value.
fn getDefault(self: Self, comptime T: type, comptime field: Field) ?T {
_ = self;
if (field.default_value) |default_value| {
if (field.default_value_ptr) |default_value| {
const anyopaque_pointer: *anyopaque = @constCast(default_value);
return @as(*T, @ptrCast(@alignCast(anyopaque_pointer))).*;
}
Expand All @@ -120,24 +120,24 @@ pub const StructEnv = struct {
/// Deserialize into a value
fn deserializeInto(self: *Self, ptr: anytype, comptime field: ?Field) !void {
const T = @TypeOf(ptr);
comptime assert(is(.Pointer)(T));
comptime assert(is(.pointer)(T));

const C = comptime meta.Child(T);

ptr.* = switch (C) {
[]const u8 => try self.deserializeString(C, field.?),
// ?[]const u8 => null,
else => switch (@typeInfo(C)) {
.Struct => try self.deserializeStruct(C),
.Enum => try self.deserializeEnum(C, field.?),
.Optional => try self.deserializeOptional(C, field.?),
.Bool => try self.deserializeBool(C, field.?),
.@"struct" => try self.deserializeStruct(C),
.@"enum" => try self.deserializeEnum(C, field.?),
.optional => try self.deserializeOptional(C, field.?),
.bool => try self.deserializeBool(C, field.?),
// .Int => |info| info.bits,
.Int => try self.deserializeInt(C, field.?),
.Float => try self.deserializeFloat(C, field.?),
.int => try self.deserializeInt(C, field.?),
.float => try self.deserializeFloat(C, field.?),
// .Array => try self.deserializeArray(C),
// .Vector => try self.deserializeVector(C),
.Pointer => try self.deserializePointer(C, field.?),
.pointer => try self.deserializePointer(C, field.?),

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

Expand All @@ -204,9 +204,9 @@ pub const StructEnv = struct {
[]const u8 => try self.allocator.dupe(u8, s),
// []const u8 => s,
else => switch (@typeInfo(C)) {
.Bool => try utils.str2bool(self.allocator, s),
.Int => try std.fmt.parseInt(C, s, 0),
.Float => try std.fmt.parseFloat(C, s, 0),
.bool => try utils.str2bool(self.allocator, s),
.int => try std.fmt.parseInt(C, s, 0),
.float => try std.fmt.parseFloat(C, s, 0),
else => @compileError("Unsupported deserialization type" ++ @typeName(C) ++ "\n"),
},
};
Expand All @@ -226,9 +226,9 @@ pub const StructEnv = struct {
const item = switch (C) {
[]const u8 => try self.allocator.dupe(u8, s),
else => switch (@typeInfo(C)) {
.Bool => s,
.Int => s,
.Float => s,
.bool => s,
.int => s,
.float => s,
else => @compileError("Unsupported deserialization type" ++ @typeName(C) ++ "\n"),
},
};
Expand Down Expand Up @@ -322,7 +322,7 @@ pub fn free(allocator: std.mem.Allocator, value: anytype) void {
[]const u8 => allocator.free(@field(value, struct_field.name)),
else => {
switch (@typeInfo(struct_field.type)) {
.Pointer => {
.pointer => {
const need_free = true;
// const cur = @field(value, struct_field.name);

Expand Down