fn CObjectDeleter(comptime initFn: anytype, comptime T: type, comptime cleanupFn: anytype) type { return struct { state: T, const Self = @This(); fn init(state: T) !Self { return Self{ .state = try initFn(), }; } fn deinit(self: *Self) void { cleanupFn(self.state); } }; } test "example usage" { var c_object_deleter = try CObjectDeleter(ntfs_inode, int, ntfs_inode_close).init(1234); defer c_object_deleter.deinit(); // ... }