-
Notifications
You must be signed in to change notification settings - Fork 784
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
Consider "impl pyo3::FromPyObject for Arc<str>" and other smart pointers #2090
Comments
One the one hand this would probably be easy to do, on the other hand, doing the |
This is exactly why I'm on the fence about this too. It would be desirable for users to not assume the wrong thing here. Note that you can achieve most of this yourself using the fn make_rc<T>(src: &PyAny) -> PyResult<Rc<T>>
where
T: for<'a> FromPyObject<'a>
{
src.extract().map(Rc::new)
}
#[pyfunction]
fn foo(
#[pyo3(from_py_with = "make_rc")]
arg: Rc<i32>,
) {
// ...
} |
Entirely possible I might be misusing or misunderstanding something, but my code right now operates on Thanks again for the help and for maintaining this awesome project! |
I think you can still use |
Wow, I didn't realize I could do that. Thanks, that worked like a charm! I think that's the definitive answer to this issue, so I'm going to close it unless you feel strongly about keeping it open. Thanks again for all the help! |
What with |
First, huge thanks to everyone that made this awesome library possible! I've been having a blast with it lately.
Right now, it seems that Rust functions callable from Python may take arguments like
i64
orString
, but cannot take smart pointer versions of those same arguments:Rc<str>, Arc<str>, Box<i64>
etc. Would it be reasonable to add that functionality, or is there some fundamental reason why it's a bad idea? At the moment, my functions have to acceptString
then internally convert toRc/Arc
to satisfy downstream APIs, and it seems like that conversion could just happen inside pyo3 itself.If anyone familiar with pyo3 internals is available to mentor, I'd be open to trying to put together a PR for this. Thanks again!
The text was updated successfully, but these errors were encountered: