Skip to content

Commit

Permalink
add child module
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Dec 1, 2023
1 parent 71959bc commit 5f8767b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
39 changes: 23 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Taken from https://pyo3.rs/v0.20.0/module.html?highlight=submodule#python-submodules
use pyo3::prelude::*;

/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}

/// A Python module implemented in Rust.
#[pymodule]
fn pdoc_pyo3_sample_library(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
fn pdoc_pyo3_sample_library(py: Python<'_>, m: &PyModule) -> PyResult<()> {

let child_module = PyModule::new(py, "child_module")?;
child_module.add_function(wrap_pyfunction!(func, child_module)?)?;
m.add_submodule(child_module)?;

Ok(())
}
}

#[pyfunction]
fn func() -> String {
"func".to_string()
}

0 comments on commit 5f8767b

Please sign in to comment.