-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.rs
50 lines (44 loc) · 1.14 KB
/
utils.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
use pyo3::types::{PyAnyMethods, PyList, PyListMethods};
use pyo3::{Bound, PyResult};
pub(crate) fn pylist_to_string_slice(pylist: Bound<PyList>) -> PyResult<Vec<String>> {
let mut strings = Vec::new();
for item in pylist.iter() {
let s: String = item.extract()?;
strings.push(s);
}
Ok(strings)
}
macro_rules! create_interface {
($name: ident, $type: ident) => {
#[pyclass(frozen)]
#[derive(Debug, Clone)]
pub struct $name {
inner: $type,
}
impl $name {
pub(crate) fn from(origin: $type) -> Self {
Self {
inner: origin,
}
}
}
};
}
macro_rules! create_interface_no_clone {
($name: ident, $type: ident) => {
#[pyclass(frozen)]
#[derive(Debug)]
pub struct $name {
inner: $type,
}
impl $name {
pub(crate) fn from(origin: $type) -> Self {
Self {
inner: origin,
}
}
}
};
}
pub(crate) use create_interface;
pub(crate) use create_interface_no_clone;