Last active
January 28, 2020 17:30
-
-
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'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 =)