Comptime Interface testing

Here is a start of comptime code that will test a struct to see if it contains all the fields and delcs of another struct. I ideally you also want to extend this for unions, error sets, and all other types. Function parameters might also have interfaces in them too that need to be recursively checked. This works for basic types and is a basic start:

const Iface = struct {
    b: u32,
    fn funca(_: u8, _: u32) bool {
        return true;
    }
    fn funcb(_: []u8) u32 {
        return 0;
    }
};

const Class = struct {
    a: u32,
    b: u32,

    fn funca(_: u8, _: u32) bool {
        return true;
    }
    fn funcc() void {}
    fn funcb(_: []u8) u32 {
        return 0;
    }
};

fn get_field(comptime class: type, comptime name: []const u8) ?std.builtin.Type.StructField {
    const ti = @typeInfo(class).Struct;
    inline for (ti.fields) |f| {
        if (std.mem.eql(u8, name, f.name)) {
            return f;
        }
    }
    return null;
}

fn has_interface(comptime iface: type, comptime class: type) bool {
    const iti = @typeInfo(iface).Struct;
    inline for (iti.decls) |i| {
        const x = @field(iface, i);
        const y = @field(class, i);
        if (!std.meta.eql(@TypeOf(x), @TypeOf(y)))
            return false;
    }
    inline for (iti.fields) |i| {
        const fi = get_field(class, i.name);
        if (fi == null or !std.meta.eql(i.type, fi.?.type))
            return false;
    }
    return true;
}

test "same" {
    std.debug.print("\n{}\n", .{has_interface(Iface, Class)});
}

You could even add a see also to documentation to point to the interface type. (I still want interfaces in the language, but this is kind of neat)