This repository has been archived by the owner on May 20, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Okay so I ended up just going and doing this with a proc macro.
I was reluctant to go this route because generally adding a proc macro for something this minor is bad, because normally you don't already have proc macros, and so you're bringing in a bunch of new dependencies, and it can significantly impact compile time. Since we're already building
otspec_macros
, however, adding one more doesn't feel that bad.So this adds a
Tag
type (struct Tag([u8; 4])
) and atag!
macro, that takes a&str
literal, and verifies at compile time that it is a valid tag.tag!("URD") == b"URD "
.0x20..=0x7E
If either of those things is false, then code won't compile.
The main advantage to this approach is that you can print a tag and know it's valid utf-8, and that all tags are generated statically at compile time. (If you need to create one at runtime you can do
Tag::from_raw("hi").unwrap()
).Overall I think this is... okay? it works, and is clear. I'm annoyed that it ended up being so much code, especially since I would like to make it much easier to grab commonly used tables, which would let me delete a lot of these changes.
One note: there's currently a weird thing where the macro is re-exported from
otspec::types
, which is itself reexported atfonttools
root. This means that if you usefonttools::types::!("hi")
it will be a compiler error ifotspec
is not in yourCargo.toml
. I'm not sure what the best solution is for this (probably just only exporting the macro viafonttools
?) but I'm going to leave it as-is for now, because I want to go for a walk before the sun goes down.cheers!