From 938b3ff7787a3e99bc41cac9add5ff25835eee22 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Thu, 17 Jan 2019 15:52:45 +0100 Subject: Refactored the arg iterators to new be static interface implementations * This makes arg iterators easier to understand and implement * It should also be faster than using the fieldToParent builtin --- src/streaming.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/streaming.zig') diff --git a/src/streaming.zig b/src/streaming.zig index f33fd96..babc573 100644 --- a/src/streaming.zig +++ b/src/streaming.zig @@ -28,7 +28,7 @@ pub fn Arg(comptime Id: type) type { /// A command line argument parser which, given an ::ArgIterator, will parse arguments according /// to the ::params. ::StreamingClap parses in an iterating manner, so you have to use a loop together with /// ::StreamingClap.next to parse all the arguments of your program. -pub fn StreamingClap(comptime Id: type, comptime ArgError: type) type { +pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type { return struct { const State = union(enum) { Normal, @@ -41,10 +41,10 @@ pub fn StreamingClap(comptime Id: type, comptime ArgError: type) type { }; params: []const clap.Param(Id), - iter: *args.Iterator(ArgError), + iter: *ArgIterator, state: State, - pub fn init(params: []const clap.Param(Id), iter: *args.Iterator(ArgError)) @This() { + pub fn init(params: []const clap.Param(Id), iter: *ArgIterator) @This() { var res = @This(){ .params = params, .iter = iter, @@ -189,8 +189,8 @@ pub fn StreamingClap(comptime Id: type, comptime ArgError: type) type { } fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, results: []const Arg(u8)) void { - var arg_iter = args.SliceIterator.init(args_strings); - var c = StreamingClap(u8, args.SliceIterator.Error).init(params, &arg_iter.iter); + var iter = args.SliceIterator.init(args_strings); + var c = StreamingClap(u8, args.SliceIterator).init(params, &iter); for (results) |res| { const arg = (c.next() catch unreachable) orelse unreachable; -- cgit v1.2.3