Replies: 1 comment
-
Interesting. The modules need to be pure Rust, and PyO3 code be only in
pub fn sum_as_string(a: i8, b: i8) -> String {
(a + b).to_string()
}
use pyo3::prelude::{pyfunction, pymodule, Bound, PyModule, PyResult};
use pyo3::wrap_pyfunction;
mod utility {
pub mod sum_as_string;
}
use utility::sum_as_string::sum_as_string;
#[pyfunction]
fn sumasstring(a: i8, b: i8) -> PyResult<String> {
Ok(sum_as_string(a, b))
}
#[pymodule]
fn iron(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sumasstring, m)?)?;
Ok(())
} Is this it, or is there a better way to do this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have this package structure:
lib.rs
has the following code:And
sum_as_string.rs
has the following code:That code emits the error:
Neither of the two suggested
use
s in either file solves the problem; neither doesuse pyo3::prelude::*;
.How can update the code to use the imported function?
Beta Was this translation helpful? Give feedback.
All reactions