##// END OF EJS Templates
rust-pyo3: facility for submodule registration, using it for dagop...
rust-pyo3: facility for submodule registration, using it for dagop It turns out that PyO3 has the exact same problem that we encountered long ago with rust-cpython. The only difference is that the value of `__name__` is not within the `mercurial` package at this point of registration. We reimplement the solution (equivalent to the suggestions in PyO3 issue tracker anyway), this time in a generic module to limit the amount of boilerplate in subsequent applications.

File last commit:

r53304:c5128c54 default
r53304:c5128c54 default
Show More
lib.rs
19 lines | 539 B | application/rls-services+xml | RustLexer
use pyo3::prelude::*;
mod dagops;
mod util;
#[pymodule]
fn pyo3_rustext(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add(
"__doc__",
"Mercurial core concepts - Rust implementation exposed via PyO3",
)?;
// the module's __name__ is pyo3_rustext, not mercurial.pyo3_rustext
// (at least at this point).
let name: String = m.getattr("__name__")?.extract()?;
let dotted_name = format!("mercurial.{}", name);
m.add_submodule(&dagops::init_module(py, &dotted_name)?)?;
Ok(())
}