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
Is it currently possible to return a reference to self as a PyResult? Currently I can return a struct with a PyResult, but get an error when trying to return a reference.
#[pyclass]
#[derive(Clone, Copy)]
struct Test {}
#[pymethods]
impl Test {
fn test_self(self) -> PyResult<Test> {
Ok(self)
}
fn test_self_reference(&self) -> PyResult<&Test> {
Ok(self)
}
fn test_self_mut_reference(&mut self) -> PyResult<&mut Test> {
Ok(self)
}
}
error[E0277]: the trait bound `std::result::Result<&Test, pyo3::err::PyErr>: pyo3::derive_utils::IntoPyResult<_>` is not satisfied
--> src\lib.rs:21:1
|
21 | #[pymethods]
| ^^^^^^^^^^^^ the trait `pyo3::derive_utils::IntoPyResult<_>` is not implemented for `std::result::Result<&Test, pyo3::err::PyErr>`
error[E0277]: the trait bound `std::result::Result<&mut Test, pyo3::err::PyErr>: pyo3::derive_utils::IntoPyResult<_>` is not satisfied
--> src\lib.rs:21:1
|
21 | #[pymethods]
| ^^^^^^^^^^^^ the trait `pyo3::derive_utils::IntoPyResult<_>` is not implemented for `std::result::Result<&mut Test, pyo3::err::PyErr>`
I was able to find the source code for it here https://github.com/PyO3/pyo3/blob/master/src/derive_utils.rs, but didn't see any documentation related to it. Is it currently possible to return a reference to self? Returning a struct works when it derives Clone and Copy, but is it possible to return a reference for structs that contain fields that don't derive from Clone/Copy? Any information would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
@kngwyu Thanks for the quick response. Your example works perfectly, so I'll use that for now and switch it over once the PR you made is accepted. Thanks for the help!
Is it currently possible to return a reference to self as a PyResult? Currently I can return a struct with a PyResult, but get an error when trying to return a reference.
I was able to find the source code for it here https://github.com/PyO3/pyo3/blob/master/src/derive_utils.rs, but didn't see any documentation related to it. Is it currently possible to return a reference to self? Returning a struct works when it derives Clone and Copy, but is it possible to return a reference for structs that contain fields that don't derive from Clone/Copy? Any information would be greatly appreciated.
The text was updated successfully, but these errors were encountered: