-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathderive_utils.rs
More file actions
33 lines (28 loc) · 977 Bytes
/
Copy pathderive_utils.rs
File metadata and controls
33 lines (28 loc) · 977 Bytes
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
//! Functionality for the code generated by the derive backend
use crate::{types::PyModule, Python};
/// Enum to abstract over the arguments of Python function wrappers.
pub enum PyFunctionArguments<'a> {
Python(Python<'a>),
PyModule(&'a PyModule),
}
impl<'a> PyFunctionArguments<'a> {
pub fn into_py_and_maybe_module(self) -> (Python<'a>, Option<&'a PyModule>) {
match self {
PyFunctionArguments::Python(py) => (py, None),
PyFunctionArguments::PyModule(module) => {
let py = crate::PyNativeType::py(module);
(py, Some(module))
}
}
}
}
impl<'a> From<Python<'a>> for PyFunctionArguments<'a> {
fn from(py: Python<'a>) -> PyFunctionArguments<'a> {
PyFunctionArguments::Python(py)
}
}
impl<'a> From<&'a PyModule> for PyFunctionArguments<'a> {
fn from(module: &'a PyModule) -> PyFunctionArguments<'a> {
PyFunctionArguments::PyModule(module)
}
}