Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macro #17

Closed
sffc opened this issue Jul 27, 2020 · 2 comments · Fixed by #18
Closed

Add macro #17

sffc opened this issue Jul 27, 2020 · 2 comments · Fixed by #18

Comments

@sffc
Copy link
Collaborator

sffc commented Jul 27, 2020

When using TinyStr, I find that I often want to write strings that should be statically compiled to a TinyStr. Instead, I have to pick between parsing the strings into TinyStr at runtime, or hard-coding the bits into my source file. It would be much nicer if I could do

tiny_str_4!("root");

and have that automatically compile to the TinyStr4 representation of that string (or fail to compile if the string is invalid).

@zbraniecki
Copy link
Owner

Ehh, yeah, I also would love to be able to construct them from str. I wish the const functions were advanced enough to give us that for free, but we're not there yet.

Pending:

I guess until then we could add tinystr-macros crate that would hold the relevant proc-macros.

@sffc
Copy link
Collaborator Author

sffc commented Jul 27, 2020

If it works, a compromise might be a macro_rules! with a signature such as

checked_tiny_str_4!(0x746F6F72, "root");

Inside the macro, you create a TinyStr using new_unchecked, and then const_assert! that the dereferenced TinyStr equals the string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants