-
Notifications
You must be signed in to change notification settings - Fork 20
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
Constant delegation #81
Conversation
I decided to generate the constant getter for each match arm since it's a Another approach that could work would be to generate the getter once before the match statement. |
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.
Thanks! The implementation looks pretty good. Left a few nits, but otherwise it's close to being ready I think.
I decided to generate the constant getter for each match arm since it's a const fn and will get optimized out by the compiler.
This is fine, we should generate the function locally, so that e.g. this works:
#[test]
fn multiple_consts() {
trait Foo {
const A: u32;
const B: u32;
}
struct A;
impl Foo for A {
const A: u32 = 0;
const B: u32 = 0;
}
struct Wrapper(A);
impl Wrapper {
delegate! {
to &self.0 {
#[const(Foo::A)]
fn a(&self) -> u32;
#[const(Foo::B)]
fn b(&self) -> u32;
}
}
}
}
Could you please add the above as a test? Thanks!
Thanks for the review, PR updated, let me know if I forgot something (in which case I'm sorry 😅) |
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 that you forgot an empty comment on one line. Once you remove it, please squash the commits into one and we're good to go :)
src/lib.rs
Outdated
@@ -945,6 +990,7 @@ pub fn delegate(tokens: TokenStream) -> TokenStream { | |||
#(#attrs)* | |||
#inline | |||
#visibility #signature { | |||
// |
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.
Forgotten line? :)
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.
Crap it was my marker for where I could inject the constant getter if you asked for it 🤣😅
Reformatting is also needed (see CI). |
should be good 👍 |
Thanks! Could you please squash the commits now? |
eafe967
to
6e96a99
Compare
done ✅ |
6e96a99
to
5273fb4
Compare
Thank you! :) |
fixes: #79
Hi, I think I got it working 😁.
Let me know if anything needs to be changed, if you have other test suggestions or a better documentation !