1//! Functionality for the code generated by the derive backend
2
3use crate::{types::PyModule, Python};
4
5/// Enum to abstract over the arguments of Python function wrappers.
6pub enum PyFunctionArguments<'a> {
7 Python(Python<'a>),
8 PyModule(&'a PyModule),
9}
10
11impl<'a> PyFunctionArguments<'a> {
12 pub fn into_py_and_maybe_module(self) -> (Python<'a>, Option<&'a PyModule>) {
13 match self {
14 PyFunctionArguments::Python(py: Python<'_>) => (py, None),
15 PyFunctionArguments::PyModule(module: &PyModule) => {
16 let py: Python<'_> = module.py();
17 (py, Some(module))
18 }
19 }
20 }
21}
22
23impl<'a> From<Python<'a>> for PyFunctionArguments<'a> {
24 fn from(py: Python<'a>) -> PyFunctionArguments<'a> {
25 PyFunctionArguments::Python(py)
26 }
27}
28
29impl<'a> From<&'a PyModule> for PyFunctionArguments<'a> {
30 fn from(module: &'a PyModule) -> PyFunctionArguments<'a> {
31 PyFunctionArguments::PyModule(module)
32 }
33}
34