From f5fd24fb765df938816063acf2190cfe8f049b26 Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 23 Oct 2022 18:16:10 +0100 Subject: [PATCH] Clarify "meta" submodule doc comment and tidy up Function type --- src/core/main.zig | 2 +- src/core/meta.zig | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/main.zig b/src/core/main.zig index 0aa7691..602ea7b 100644 --- a/src/core/main.zig +++ b/src/core/main.zig @@ -5,7 +5,7 @@ pub const io = @import("./io.zig"); /// -/// Metaprogramming introspection utilities +/// Metaprogramming introspection and generation utilities. /// pub const meta = @import("./meta.zig"); diff --git a/src/core/meta.zig b/src/core/meta.zig index 22b38eb..884c4a4 100644 --- a/src/core/meta.zig +++ b/src/core/meta.zig @@ -12,13 +12,12 @@ pub fn FnReturn(comptime Fn: type) type { } /// -/// Returns a single-input single-output closure type where `Input` represents the input type, -/// `Output` represents the output type, and `captures_size` represents the size of the closure -/// context. +/// Returns a single-input single-output closure type where `In` represents the input type, `Out` +/// represents the output type, and `captures_size` represents the size of the closure context. /// -pub fn Function(comptime captures_size: usize, comptime Input: type, comptime Output: type) type { +pub fn Function(comptime captures_size: usize, comptime In: type, comptime Out: type) type { return struct { - applyErased: fn (*anyopaque, Input) Output, + applyErased: fn (*anyopaque, In) Out, context: [captures_size]u8, /// @@ -29,7 +28,7 @@ pub fn Function(comptime captures_size: usize, comptime Input: type, comptime Ou /// /// Applies `input` to `self`, producing a result according to the current context data. /// - pub fn apply(self: *Self, input: Input) Output { + pub fn apply(self: *Self, input: In) Out { return self.applyErased(&self.context, input); } @@ -39,7 +38,7 @@ pub fn Function(comptime captures_size: usize, comptime Input: type, comptime Ou /// /// The newly created [Self] is returned. /// - pub fn capture(captures: anytype, comptime call: fn (@TypeOf(captures), Input) Output) Self { + pub fn capture(captures: anytype, comptime call: fn (@TypeOf(captures), In) Out) Self { const Captures = @TypeOf(captures); if (@sizeOf(Captures) > captures_size) @@ -52,7 +51,7 @@ pub fn Function(comptime captures_size: usize, comptime Input: type, comptime Ou .context = undefined, .applyErased = struct { - fn do(erased: *anyopaque, input: Input) Output { + fn do(erased: *anyopaque, input: In) Out { return call(@ptrCast(*Captures, @alignCast( captures_align, erased)).*, input); }