Skip to content

Instantly share code, notes, and snippets.

@metaleap
Last active January 28, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaleap/dc0464f60b2dd6142349a16e41f58a9e to your computer and use it in GitHub Desktop.
Save metaleap/dc0464f60b2dd6142349a16e41f58a9e to your computer and use it in GitHub Desktop.
./main.zig:4:26: error: expected type 'struct:11:32', found 'struct:11:32'
const std = @import("std");
pub fn main() void {
var sess = Protocol(.{
.TIn = MyIn,
.TOut = MyOut,
}){};
sess.serve(); // forever-loop
}
pub fn Protocol(comptime spec: struct {
TIn: type,
TOut: type,
}) type {
return struct {
subscribers: [@memberCount(spec.TIn)]?usize = ([_]?usize{null}) ** @memberCount(spec.TIn),
pub fn on(self: *@This()) void {} // subscription
pub fn serve(self: *@This()) void {} // transport-dealing forever-loop
};
}
pub const MyIn = union(enum) {
foo: fn (isize) bool,
bar: fn (bool) isize,
};
pub const MyOut = union(enum) {
baz: fn ([]u8) void,
};
@metaleap
Copy link
Author

Of course if you take out the spec: struct into a separate named def, no problems. But I thought we had structurual not nominal typing =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment