Application Context Implementation #4
|
@ -5,7 +5,7 @@
|
|||
pub const io = @import("./io.zig");
|
||||
|
||||
///
|
||||
/// Metaprogramming introspection utilities
|
||||
/// Metaprogramming introspection and generation utilities.
|
||||
///
|
||||
pub const meta = @import("./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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue