-
I would like to create a function returning a generic type that is built from a #[derive(FromPyObject)]
pub struct Test {
pub first: String,
pub second: String,
}
pub fn from_py_generic<'a, T: FromPyObject<'a>>(obj: Py<PyAny>) -> PyResult<T> {
Python::with_gil(|py| obj.extract(py))
} This fails to compile with the following error:
What is weird is that the following code compiles without errors: pub fn from_py(obj: Py<PyAny>) -> PyResult<Test> {
Python::with_gil(|py| obj.extract(py))
}
pub fn from_py_generic_pyclass<'a, T: PyClass + Clone>(obj: Py<PyAny>) -> PyResult<T> {
Python::with_gil(|py| obj.extract(py)) // There is an impl of FromPyObject for T: Pyclass + Clone
} I would like to avoid implementing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Try using pub fn from_py_generic<T: for <'a> FromPyObject<'a>>(obj: Py<PyAny>) -> PyResult<T> {
Python::with_gil(|py| obj.extract(py))
} |
Beta Was this translation helpful? Give feedback.
Try using