Funtions used in place of interfaces?

I am trying to understand how interfaces are done within Zig. Looking at the source for writer/reader, but still confused. There is not much documentation on this topic, or functions. The code below works, but not the two other techniques commented out. ie. Function as a var, and functions being created within a function. Am I on the right path, regarding interfaces, ie. that I would return a common fn from structs rather than have some kind of base class struct?

const std = @import("std");

pub fn main() anyerror!void {

pub fn blah(p: u16) void {
    const x = 9;"{d} + {d} = {d}", .{ p, x, p + x });

pub fn thisReturnsAfn() fn (u16) void {
    return blah;

// var vFn: fn (u16) void = fn(p: u16) void {
//     const x = 9;
//"{d} + {d} = {d}", .{ p, x, p + x });
// };

// pub fn thisReturnsALocalfn() fn (u16) void {
//     return fn(p: u16) void {
//         const x = 9;
//"{d} + {d} = {d}", .{ p, x, p + x });
//     };
// }

This thread covers some ground on this topic. Specifically this post links a video that if you haven’t seen it already, I highly recommend watching it. It helped me a lot in understanding how with Zig there’s no single way to implement interfaces. Also of note is the latter part of the video which covers some benchmarks comparing the different methods shown, I was quite surprised with the results!

Thanks for the info. I realise now as well that my two commented out ‘fn’ blocks would require allocations, which I guess is why that syntax is not handled. Lots to learn :slight_smile: