Handle generics in NativeScript derive and #[methods]#983
Conversation
This is useful mainly for skipping marker fields in generic code.
Bromeon
left a comment
There was a problem hiding this comment.
Very nice addition! I especially like how you found a way to use the natural type-aliases to register monomorphizations:
#[gdnative::derive::monomorphize]
type IntPair = Pair<i32>;I was first under the impression this would need to happen in the scope of the NativeClass macro itself.
Proc-macro code for To/FromVariant has reached quite a complexity already, but I think that's in the nature of proc-macros. Those two traits have become very powerful in the meantime, with lots of serde-like features! 💪
Would you add monomorphize to the prelude, or do you think it's rare enough to deserve a qualified import/path?
| if !status: | ||
| printerr(" !! _test_generic_class failed") | ||
|
|
||
| return status No newline at end of file |
There was a problem hiding this comment.
Maybe add newline at end of file?
The derive macros are now aware of both lifetime and type parameters. `'static` bounds are added to both kinds, which improves the error message shown when a user tries to put a lifetime into a NativeClass. This behavior is chosen because unlike type parameters, lifetime parameters aren't very useful in this context: only `'static` would be supported anyway, and any attempted usage is hightly likely to have originated from user error.
aee97b0 to
81e1bff
Compare
Admittedly, there is indeed a lot of complexity in those two macros. It's more of an unfortunate consequence of Godot having a richer data model than what serde allows (
I don't think it's prelude-worthy. It isn't something you'd expect to use in every other file in the average project. |
|
I'll be merging this in a day, in case there are no further comments. |
|
bors try |
tryBuild succeeded: |
|
bors r+ |
|
Build succeeded: |
The derive macros are now aware of both lifetime and type parameters.
'staticbounds are added to both kinds, which improves the error message shown when a user tries to put a lifetime into a NativeClass.This behavior is chosen because unlike type parameters, lifetime parameters aren't very useful in this context: only
'staticwould be supported anyway, and any attempted usage is hightly likely to have originated from user error.Also added the
#[skip]attribute for skipping fields inFromVarargs. This is useful mainly for skipping marker fields in generic code.Close #601
Error message
The error message that appears when lifetime parameters are declared for
NativeClasstypes now clearly indicate where the problem lies and what the expectations are:Compares this with the old error message:
Close #174