-
-
Notifications
You must be signed in to change notification settings - Fork 25
Implement generic assert_impl macro
#28
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
Conversation
|
There are a few limitations to the syntax due to macro shenanigans. Maybe we should make a proc_macro instead. |
|
This subsumes #27. |
|
Since the |
|
I just saw that #26 had a similar idea. I could use const booleans too actually, as long as I can recover pretty error messages |
|
This is awesome!! One of my plans for 2.0 was to consolidate the
I can only imagine you've been squinting for quite some time. I'm very impressed by you being able to do this. I'll read through the implementation when I have more time this weekend to make sense of your In the meantime, could you extract the bits that emit My plan is to adopt this nicer syntax in a 1.x version and deprecate the others to be removed in 2.0. |
I'm not sure what you mean :/
I am in the process of using the newly defined |
|
So the error message here shows: I was saying I'd like that for the old macros. But it seems that you've redefined the other macros to use this new macro instead. So I imagine you'd get that for free. |
The Deref trick used in `assert_impl_any` can be generalized, and we get a general way of checking whether `$type: $trait` that can be used to implement most of the `assert_impl_*` and `assert_sub_*` macros.
This subsumes a few more impl macros
cf004c8 to
7fdc5d9
Compare
|
Rebased on master and now we got the pretty errors |
|
Thanks! I'll definitely try to check this out soon. Your |
|
We probably don't need that much structure on |
As a nice side-effect, we don't need the local booleans to secure against blanket impls.
|
Ugh I hit an ICE rust-lang/rust#62708 when trying to use const bool instead of type-level bools :( |
|
Ok, so now it's easy to get a const type-level boolean testing whether a type implements a particular bunch of traits (that's what the hidden |
|
Sorry I haven't gotten back to you on this. Life got in the way. I'll review this soon, I promise! |
|
Hey @Nadrieril thanks again for this PR! ❤️ I finally got around to looking through it and I'm happy with the implementation. Apologies for it taking so long to review. A new version will be released soon with this macro! |
They made the initial `does_impl` implementation, which can be found at nvzqz/static-assertions#28.
Inspired by nvzqz/static-assertions#28 but it takes a much simpler approach. This supports the boolean operators: | (OR), & (AND), ^ (XOR), ! (NOT). It also allows for parentheses (with nesting). Unlike that in `static_assertions`, it: - Handles operators in the correct order of precedence. This is because it uses the operators defined on `bool` directly, and thus does not need to redefine them on `True` and `False`, also reducing complexity. - Removes the need to parenthesize traits with generic parameters. This is done by handling generic parsing directly when the operator can't be parsed right after a `path` (& and ^; | seems to work fine).
|
@Nadrieril I rewrote the macro and fixed all of the issues with it! And I decided to put it into its own library at https://github.com/nvzqz/impls. I credited you as co-author in the |
|
That's great ! You seem to have dropped support for generics though ? |
|
@nvzqz I was surprised to see the missing support for |
|
Upon further investigation, it looks like the issue is that the commits after November 3, 2019 were never released to crates.io. |
|
@nvzqz Can you please release the latest changes on crates.io? I realize the functionality of this crate is quite stable, but this feature would help me a lot. Happy to help if needed. |
After squinting for a while at the wrapper trick for
assert_impl_any, it turns out it generalizes quite well. I implemented a genericassert_implmacro with type-level booleans that covers most of the cases where we want to check for a type implementing a set of traits.Examples:
The error messages are also quite nice: