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]
24#[pyo3_stub_gen::derive::gen_stub_pymethods]
25impl DatabentoStatisticType {
26 #[new]
28 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
29 let t = Self::type_object(py);
30 Self::py_from_str(&t, value).map_err(to_pyvalue_err)
31 }
32
33 const fn __hash__(&self) -> isize {
34 *self as isize
35 }
36
37 fn __repr__(&self) -> String {
38 format!(
39 "<{}.{}: '{}'>",
40 stringify!(DatabentoStatisticType),
41 self.name(),
42 self.value(),
43 )
44 }
45
46 fn __str__(&self) -> String {
47 self.to_string()
48 }
49
50 #[getter]
51 #[must_use]
52 pub fn name(&self) -> String {
53 self.to_string()
54 }
55
56 #[getter]
57 #[must_use]
58 pub const fn value(&self) -> u8 {
59 *self as u8
60 }
61
62 #[classmethod]
68 #[pyo3(name = "from_str")]
69 fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
70 let data_str: &str = data.extract()?;
71 let tokenized = data_str.to_uppercase();
72 Self::from_str(&tokenized).map_err(to_pyvalue_err)
73 }
74}
75
76#[pymethods]
77#[pyo3_stub_gen::derive::gen_stub_pymethods]
78impl DatabentoStatisticUpdateAction {
79 #[new]
81 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
82 let t = Self::type_object(py);
83 Self::py_from_str(&t, value).map_err(to_pyvalue_err)
84 }
85
86 const fn __hash__(&self) -> isize {
87 *self as isize
88 }
89
90 fn __repr__(&self) -> String {
91 format!(
92 "<{}.{}: '{}'>",
93 stringify!(DatabentoStatisticUpdateAction),
94 self.name(),
95 self.value(),
96 )
97 }
98
99 fn __str__(&self) -> String {
100 self.to_string()
101 }
102
103 #[getter]
104 #[must_use]
105 pub fn name(&self) -> String {
106 self.to_string()
107 }
108
109 #[getter]
110 #[must_use]
111 pub const fn value(&self) -> u8 {
112 *self as u8
113 }
114
115 #[classmethod]
121 #[pyo3(name = "from_str")]
122 fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
123 let data_str: &str = data.extract()?;
124 let tokenized = data_str.to_uppercase();
125 Self::from_str(&tokenized).map_err(to_pyvalue_err)
126 }
127}