Clarify "meta" submodule doc comment and tidy up Function type
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kayomn 2022-10-23 18:16:10 +01:00
parent 196a3d1200
commit f5fd24fb76
2 changed files with 8 additions and 9 deletions

View File

@ -5,7 +5,7 @@
pub const io = @import("./io.zig"); pub const io = @import("./io.zig");
/// ///
/// Metaprogramming introspection utilities /// Metaprogramming introspection and generation utilities.
/// ///
pub const meta = @import("./meta.zig"); pub const meta = @import("./meta.zig");

View File

@ -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, /// Returns a single-input single-output closure type where `In` represents the input type, `Out`
/// `Output` represents the output type, and `captures_size` represents the size of the closure /// represents the output type, and `captures_size` represents the size of the closure context.
/// 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 { return struct {
applyErased: fn (*anyopaque, Input) Output, applyErased: fn (*anyopaque, In) Out,
context: [captures_size]u8, 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. /// 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); 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. /// 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); const Captures = @TypeOf(captures);
if (@sizeOf(Captures) > captures_size) if (@sizeOf(Captures) > captures_size)
@ -52,7 +51,7 @@ pub fn Function(comptime captures_size: usize, comptime Input: type, comptime Ou
.context = undefined, .context = undefined,
.applyErased = struct { .applyErased = struct {
fn do(erased: *anyopaque, input: Input) Output { fn do(erased: *anyopaque, input: In) Out {
return call(@ptrCast(*Captures, @alignCast( return call(@ptrCast(*Captures, @alignCast(
captures_align, erased)).*, input); captures_align, erased)).*, input);
} }