Skip to content

Instantly share code, notes, and snippets.

@lmb

lmb/example.zig Secret

Created July 17, 2018 09:20
Show Gist options
  • Save lmb/f5444ac96b7e3d0ab860682315cad5f4 to your computer and use it in GitHub Desktop.
Save lmb/f5444ac96b7e3d0ab860682315cad5f4 to your computer and use it in GitHub Desktop.
zig comptime return
fn makeToken(comptime id: Identifier, comptime data: []const u8) []const u8 {
comptime {
assert(data.len < longFormMin);
return makeIdentifier(id) ++ []u8{
@truncate(u8, data.len),
} ++ data;
}
}
fn makeIdentifier(comptime id: Identifier) []const u8 {
comptime {
const number = id.tag.number();
assert(number < multipartNumber);
return []u8{
u8(@enumToInt(id.tag.class()))<<6 | u8(@enumToInt(id.encoding))<<5 | @truncate(u8, number),
};
}
}
test "bloop" {
comptime const data = makeToken(A, []u8{0}); // error here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment