Skip to content

Instantly share code, notes, and snippets.

@joseph-montanez
Created October 16, 2024 01:25
Show Gist options
  • Save joseph-montanez/cd63c959c017c43119689d9157ad7bf2 to your computer and use it in GitHub Desktop.
Save joseph-montanez/cd63c959c017c43119689d9157ad7bf2 to your computer and use it in GitHub Desktop.
Anonymous Struct Functions
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