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