rustitude/
lib.rs

1#![allow(non_snake_case)]
2#![allow(non_camel_case_types)]
3use pyo3::prelude::*;
4mod amplitude;
5mod dataset;
6mod four_momentum;
7mod gluex;
8mod manager;
9
10#[macro_export]
11macro_rules! impl_convert {
12    ($a:ty, $b:ty) => {
13        impl From<$b> for $a {
14            fn from(value: $b) -> Self {
15                Self(value)
16            }
17        }
18        impl From<$a> for $b {
19            fn from(value: $a) -> Self {
20                value.0
21            }
22        }
23    };
24}
25
26pub fn add_submodule<F>(parent: &Bound<'_, PyModule>, name: &str, mod_init: F) -> PyResult<()>
27where
28    F: Fn(&Bound<'_, PyModule>) -> PyResult<()>,
29{
30    let child_module = PyModule::new_bound(parent.py(), name)?;
31    mod_init(&child_module)?;
32    parent.add(name.split('.').last().unwrap(), &child_module)?;
33    parent
34        .py()
35        .import_bound("sys")?
36        .getattr("modules")?
37        .set_item(name, &child_module)?;
38    Ok(())
39}
40
41#[pymodule]
42#[pyo3(name = "_rustitude")]
43fn rustitude(m: &Bound<'_, PyModule>) -> PyResult<()> {
44    m.add("__version__", env!("CARGO_PKG_VERSION"))?;
45    add_submodule(m, "rustitude.dataset", dataset::pyo3_module)?;
46    add_submodule(m, "rustitude.four_momentum", four_momentum::pyo3_module)?;
47    add_submodule(m, "rustitude.amplitude", amplitude::pyo3_module)?;
48    add_submodule(m, "rustitude.manager", manager::pyo3_module)?;
49
50    add_submodule(m, "rustitude.gluex", gluex::pyo3_module)?;
51    Ok(())
52}