In another project I've defined a struct ValueType:
#[derive(Clone, PartialEq, Debug)]
pub enum ValueType {
Int(i64),
Hex(u64),
Float(f64),
String(String),
}
In the current project I want to extend this type to support into_py. So I've extended it as follows:
struct PyValueType(ValueType);
impl ToPyObject for PyValueType
{
fn to_object(&self, py: Python) -> PyObject {
match self {
PyValueType(ValueType::Int(v)) => v.into_py(py),
PyValueType(ValueType::Hex(v)) => v.into_py(py),
PyValueType(ValueType::Float(v)) => v.into_py(py),
PyValueType(ValueType::String(v)) => v.into_py(py),
}
}
}
If I want to use it in a pyclass:
fn foo(slf: PyRef<Self>) -> PyResult<PyObject> {
let gil = Python::acquire_gil();
let py = gil.python();
Ok(PyValueType(ValueType::Int(5).clone()).into_py(py))
}
I get the following error:
the method `into_py` exists for struct `PyValueType`, but its trait bounds were not satisfied
method cannot be called on `PyValueType` due to unsatisfied trait bounds
note: the following trait bounds were not satisfied:
`PyValueType: pyo3::AsPyPointer`
which is required by `&PyValueType: pyo3::IntoPy<pyo3::Py<pyo3::PyAny>>`
How can I solve this issue?