You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fails with the trait pyo3::callback::IntoPyCallbackOutput<_> is not implemented for &[u32]. Which happens because IntoPy<PyObject> is only implemented for Vec<T> where T: IntoPy<PyObject>. It's currently not possible to add an implementation for &[T] where T: IntoPy<PyObject> because there is a specialized implementation for PyBytes: impl<'a> IntoPy<PyObject> for &'a [u8].
I tried switching this implementation to IntoPy<&PyBytes> but so far haven't been succesful because of lifetime mismatches.
It's possible to work around this issue in user code by converting the slice to PyObject through to_object(py), but I think it'd be more ergonomic (and prevent unnecessary copies in user code) if slices could be converted automatically. I've seen this a few times already that Rust functions call to_vec() on a slice in order to get compiling code since Vec<T> has the IntoPy implementation.
A possible approach would be specifying a lifetime on the Python argument in IntoPy. Then we can write the following:
I've been thinking about this too. I agree it'd be very nice to have full slice support.
I think that it could be hard to achieve this without either waiting for specialization to be stable (I think we might only need min_specialization in this case; not sure), or removing the &[u8] -> PyBytes special case.
impl<'a, 'b> IntoPy<&'b PyBytes> for &'a [u8] won't help, because really the only useful implementation of IntoPy is IntoPy<PyObject> which all our callback.rs utility code uses to convert Rust types to Python.
Currently something like
fails with
the trait pyo3::callback::IntoPyCallbackOutput<_> is not implemented for &[u32]
. Which happens becauseIntoPy<PyObject>
is only implemented forVec<T> where T: IntoPy<PyObject>
. It's currently not possible to add an implementation for&[T] where T: IntoPy<PyObject>
because there is a specialized implementation forPyBytes
:impl<'a> IntoPy<PyObject> for &'a [u8]
.I tried switching this implementation to
IntoPy<&PyBytes>
but so far haven't been succesful because of lifetime mismatches.It's possible to work around this issue in user code by converting the slice to
PyObject
throughto_object(py)
, but I think it'd be more ergonomic (and prevent unnecessary copies in user code) if slices could be converted automatically. I've seen this a few times already that Rust functions callto_vec()
on a slice in order to get compiling code sinceVec<T>
has theIntoPy
implementation.A possible approach would be specifying a lifetime on the
Python
argument inIntoPy
. Then we can write the following:But I'm not sure if this actually works because I'm getting hundreds of compilation errors from the added lifetime ;)
The text was updated successfully, but these errors were encountered: