-
Notifications
You must be signed in to change notification settings - Fork 566
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
Use a macro to implement context methods #972
Conversation
I really dislike macros for large amount of code because I propose we try to solve this using traits instead. One possible way can be seen in #974. |
/bloat |
6713aa7
to
74fa6a9
Compare
If we do continue with a macro for docs purposes, then I wonder if we can somehow have the function definitions/comments outside of the macro, and then a macro that takes a reference to the code. That way |
8fc5863
to
ce8a1b2
Compare
The alternative to a macro that would let us do something like that would be to use build.rs and do codegen. This feels a bit worse in some ways (less discoverable, maybe harder to read the code?) but would at least ensure formatting. |
I read through a bunch of rustfmt issues and apparently it does do formatting in some specific macro cases. It was unclear which though. However there might be a chance to someshow either restructure the macro or wrap individual functions in another macro to enable formatting. |
I played around with this without luck, if you've read any issues about this that have reasonable explanations I'd be all ears? |
I couldn't get it to work in relation to this PR, although I'm not experienced with macros and may be missing something. More generally I guess we can minimize the amount of formatting trouble by keeping the macro'd methods mostly lightweight shims and if we need actual work then do that in another method somewhere, e.g. on |
eda2144
to
dc93445
Compare
dc93445
to
2cb249b
Compare
This attempts to solve the issue of duplicate code and out of date documentation for methods shared between multiple contexts. The approach taken here is to use a simple macro to implement those methods. A consequence of this work is that methods are now more consistently available across more contexts; as an example, `window_id` and `window` are now available from all contexts, whereas they were previously missing from `PaintCtx` for no particular reason.
2cb249b
to
716a04c
Compare
this should now be gtg? It also has one cool property I hadn't really considered: you now need to think really consciously about what set of contexts a method should belong to, which means it will be much rarer for something to just randomly not be available on, say, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a nice consistency and maintenance improvement, now that fmt
works.
One typo but looks good overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Co-authored-by: Leopold Luley <[email protected]>
This attempts to solve the issue of duplicate code and out of
date documentation for methods shared between multiple contexts.
The approach taken here is to use a simple macro to implement
those methods.
The macro was actually a real pain to write, and kind of gross APIwise; in particular you need to pass in all of the lifetimes twice.
I've given up trying to improve it, and given that this is private API
it doesn't matter too much, but it does offend my sensibilites
somewhat.
There are a few bits of future work; window & window_id shouldbe shared between all contexts, but that requires a change to
PaintCtx; another change would let us reuse is_focused.
In any case, I think this is a step in a good direction.This is based off of #970, which should go in first.