PyRefMut<_, T>
vs &Bound<_, T>
vs T
#4991
-
Hi, Suppose we have a pure rust function in an external crate that I can't modify the source code, and which take the ownership of the passed arg.
To call this from Python,
and the following
After reading https://pyo3.rs/v0.23.5/types#pyo3s-smart-pointers, I wondered whehter this would require unnecessary copying of the py_arg.
would be more efficient. Then I also realized that the following also works
I wonder which one should be preferred in terms of performance, avoiding any unnecessary copy? And if I can update the source code to put |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
PyO3 doesn't support transfer of ownership out of Python objects and it's unlikely to be planned, see #2225
|
Beta Was this translation helpful? Give feedback.
PyO3 doesn't support transfer of ownership out of Python objects and it's unlikely to be planned, see #2225
PyRefMut<T>
and&Bound<T>
are mostly equivalent and you can use whichever you prefer.&Bound<T>
allows you to make the borrow shorter, which might be useful in concurrent situations.