#expected type '[]const u8', found '[][*:0]u8'

1 messages · Page 1 of 1 (latest)

tidal radish
#

Code: ```zig
const arg = std.os.argv[1..];
const data = json.parseFromSlice(FnCall, allocator, arg, .{ });


Error: ```
lib.zig:21:55: error: expected type '[]const u8', found '*const [][*:0]u8'
  const data = json.parseFromSlice(FnCall, allocator, arg, .{  });
                                                      ^~~
referenced by:
    callMain: /data/data/com.termux/files/usr/lib/zig/lib/std/start.zig:564:17
    initEventLoopAndCallMain: /data/data/com.termux/files/usr/lib/zig/lib/std/start.zig:508:34
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

What i did wrong?

spice pike
#

a few things
first that error doesnt make sense with the code you sent, did you pass &arg to the json function instead?
second the reason that wont work regardless is because the json function is expecting a single slice (string) but youre giving it a slice of multiple strings, what is your intention exactly?

#

well actually theres 2 reasons that wont work, the second one is that std.os.argv gives a slice of [*:0]u8 which has no length but the json function expects a []const u8, you can use std.mem.sliceTo(arg, 0) to get a slice.
though id recommend against std.os.argv directly since its not portable

tidal radish
spice pike
#

either std.process.argsAlloc which will give a slice of slices similar to os.argv or std.process.argsWithAllocator which will give an iterator over the args

tidal radish