Created
October 16, 2024 01:25
-
-
Save joseph-montanez/cd63c959c017c43119689d9157ad7bf2 to your computer and use it in GitHub Desktop.
Anonymous Struct Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn foo( | |
w: f32, | |
context: anytype, | |
callback: fn (@TypeOf(context), f32) void, | |
) void { | |
callback(context, w + 23.0); | |
} | |
pub fn main() void { | |
const name = "Joles"; | |
const bar = struct { | |
const Self = @This(); | |
name: *const [5:0]u8, | |
pub fn length(self: Self, p: f32) void { | |
std.debug.print("Hello {s} {d}", .{ self.name, p }); | |
} | |
}{ .name = name }; | |
foo(23.0, bar, @TypeOf(bar).length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment