nautilus_databento/python/
enums.rs1use std::str::FromStr;
17
18use nautilus_core::python::to_pyvalue_err;
19use pyo3::{PyTypeInfo, prelude::*, types::PyType};
20
21use crate::enums::{DatabentoStatisticType, DatabentoStatisticUpdateAction};
22
23#[pymethods]
24impl DatabentoStatisticType {
25 #[new]
26 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
27 let t = Self::type_object(py);
28 Self::py_from_str(&t, value).map_err(to_pyvalue_err)
29 }
30
31 const fn __hash__(&self) -> isize {
32 *self as isize
33 }
34
35 fn __repr__(&self) -> String {
36 format!(
37 "<{}.{}: '{}'>",
38 stringify!(DatabentoStatisticType),
39 self.name(),
40 self.value(),
41 )
42 }
43
44 fn __str__(&self) -> String {
45 self.to_string()
46 }
47
48 #[getter]
49 #[must_use]
50 pub fn name(&self) -> String {
51 self.to_string()
52 }
53
54 #[getter]
55 #[must_use]
56 pub const fn value(&self) -> u8 {
57 *self as u8
58 }
59
60 #[classmethod]
66 #[pyo3(name = "from_str")]
67 fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
68 let data_str: &str = data.extract()?;
69 let tokenized = data_str.to_uppercase();
70 Self::from_str(&tokenized).map_err(to_pyvalue_err)
71 }
72}
73
74#[pymethods]
75impl DatabentoStatisticUpdateAction {
76 #[new]
77 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
78 let t = Self::type_object(py);
79 Self::py_from_str(&t, value).map_err(to_pyvalue_err)
80 }
81
82 const fn __hash__(&self) -> isize {
83 *self as isize
84 }
85
86 fn __repr__(&self) -> String {
87 format!(
88 "<{}.{}: '{}'>",
89 stringify!(DatabentoStatisticUpdateAction),
90 self.name(),
91 self.value(),
92 )
93 }
94
95 fn __str__(&self) -> String {
96 self.to_string()
97 }
98
99 #[getter]
100 #[must_use]
101 pub fn name(&self) -> String {
102 self.to_string()
103 }
104
105 #[getter]
106 #[must_use]
107 pub const fn value(&self) -> u8 {
108 *self as u8
109 }
110
111 #[classmethod]
117 #[pyo3(name = "from_str")]
118 fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
119 let data_str: &str = data.extract()?;
120 let tokenized = data_str.to_uppercase();
121 Self::from_str(&tokenized).map_err(to_pyvalue_err)
122 }
123}