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
I am not able to add a const instance of a PyClass to a module. I tried different approaches (see lib.rs below) without success.
Cargo.toml
[package]
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "test_pyo3"
crate-type = ["cdylib"]
[dependencies.pyo3]
git = "https://github.com/PyO3/pyo3"
features = ["extension-module"]
lib.rs
use pyo3::prelude::*;#[pyclass]structTest{}constT:Test = Test{};#[pymodule]fntest_pyo3(py:Python<'_>,m:&PyModule) -> PyResult<()>{// original approach// the trait `pyo3::conversion::ToPyObject` is not implemented for `Test`
m.add("T",T)?;// cannot infer type for type parameter `V` declared on the associated function `add`
m.add("T",T.into_py(py))?;// the trait `pyo3::conversion::ToPyObject` is not implemented for `std::result::Result<pyo3::instance::Py<Test>, pyo3::err::PyErr>`
m.add("T",Py::new(py,T))?;Ok(())}
Thanks a lot!
The text was updated successfully, but these errors were encountered:
I am not able to add a
const
instance of aPyClass
to a module. I tried different approaches (see lib.rs below) without success.Cargo.toml
lib.rs
Thanks a lot!
The text was updated successfully, but these errors were encountered: