mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
std.cli: ?[]T now is null on empty slices
Signed-off-by: Pablo Alessandro Santos Hugen <phugen@redhat.com>
This commit is contained in:
parent
8f77a3b481
commit
f6a7ba6ab9
1 changed files with 8 additions and 1 deletions
|
|
@ -212,10 +212,17 @@ fn parseBool(comptime T: type, iter: *Iterator) Error!T {
|
|||
}
|
||||
|
||||
fn parseOptional(comptime T: type, iter: *Iterator, allocator: Allocator) (Error || Allocator.Error)!T {
|
||||
return parseValue(@typeInfo(T).optional.child, iter, allocator) catch |err| switch (err) {
|
||||
const ChildT = @typeInfo(T).optional.child;
|
||||
const val = parseValue(ChildT, iter, allocator) catch |err| return switch (err) {
|
||||
Error.MissingValue => null,
|
||||
else => err,
|
||||
};
|
||||
// Optional steals empty state from slices
|
||||
const child_info = @typeInfo(ChildT);
|
||||
return if (child_info == .pointer and child_info.pointer.size == .slice and val.len == 0)
|
||||
null
|
||||
else
|
||||
val;
|
||||
}
|
||||
|
||||
inline fn flagName(arg: []const u8) ?[]const u8 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue