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
53
54
55
56
57
58
59
60
use std::{collections::HashMap, ops::Deref, sync::Arc};
use pyo3::prelude::*;
#[pyclass]
#[derive(Debug, Clone)]
pub struct PyHandler {
pub func: PyObject,
pub args: usize,
pub is_coroutine: bool,
}
impl Deref for PyHandler {
type Target = PyObject;
fn deref(&self) -> &Self::Target {
&self.func
}
}
#[pyclass]
#[derive(Debug, Clone, Default)]
pub struct PyHandlers {
pub inner: HashMap<String, Arc<PyHandler>>,
}
impl Deref for PyHandlers {
type Target = HashMap<String, Arc<PyHandler>>;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
#[pyclass]
#[derive(Debug, Clone)]
pub struct PyState {
pub context: Arc<PyObject>,
}
impl PyState {
pub fn new(context: Arc<PyObject>) -> Self {
Self { context }
}
}