-
Notifications
You must be signed in to change notification settings - Fork 795
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 IntoPyObjectRef
derive macro
#4672
Conversation
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.
Great, awesome to see that this just works out! 🎉
Just a final thought - is RefIntoPyObject
or IntoPyObjectRef
better? I quite like it starting with Into
, which would suggest we stick with IntoPyObjectRef
, but the order RefIntoPyObject
feels more accurate to me as a description. 🤔
Also, thank you for just seeing my brief musing and running with it to build something which is hopefully quite convenient for users! |
I feel like there might be a way where we could use specialization inside the macro to achieve that, but I'm also happy if we defer that for a follow-up for simplicity's sake. (i.e. because |
Personally I prefer
I guess we probably could special case here, but this applies to pretty much to all types. So if this would store Maybe we can provide this blanket impl? impl<'a, 'py, T> IntoPyObject<'py> for &&'a T
where
&'a T: IntoPyObject<'py>,
{
type Target = <&'a T as IntoPyObject<'py>>::Target;
type Output = <&'a T as IntoPyObject<'py>>::Output;
type Error = <&'a T as IntoPyObject<'py>>::Error;
#[inline]
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
(*self).into_pyobject(py)
}
} |
That blanket seems like a very good idea, I can't think of a reason why a user would ever want a different implementation for Let's add that blanket before 0.23 as a follow up, maybe I can PR that quickly this morning in an hour or so... |
From #4041 (comment)
Introduces the
IntoPyObjectRef
derive macro to implementIntoPyObject
for a reference to the derived type. It pretty much uses the same code gen as the ordinaryIntoPyObject
derive macro. I have moved the relevant branches up to the root function, to avoid threading the reference condition through the whole machinery. We really only need to adjust the ident itself, generic bounds,transparent
types and introduce the named lifetime, the body works by inference and does not need changes between the two.I added this to the hygiene, roundtrip and ui tests. I skipped hygiene
IntoPyObject4
because it would needIntoPyObject for &&Bound
which we currently don't have, not sure where we want to draw the line.Closes #4041 🎉