Skip to content

Commit 8e9d12b

Browse files
committed
feat: add utility pyO3 module loader
1 parent fc9dcc0 commit 8e9d12b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

binding/python/src/utils.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::sync::OnceLock;
2+
3+
use pyo3::prelude::*;
4+
use pyo3::Bound as PyBound;
5+
use pyo3::exceptions::PyModuleNotFoundError;
6+
7+
pub(crate) fn get_module<'a>(
8+
py: Python<'a>,
9+
cell: &'static OnceLock<Py<PyModule>>,
10+
) -> PyResult<&'a PyBound<'a, PyModule>> {
11+
let module: &PyBound<'a, PyModule> = cell
12+
.get()
13+
.ok_or_else(|| PyModuleNotFoundError::new_err("Could not find module"))?
14+
.bind(py);
15+
Ok(module)
16+
}

0 commit comments

Comments
 (0)