Skip to content

Commit 32f1954

Browse files
author
AGAEV Denis E
committed
Add macro for geo types
1 parent 227cecc commit 32f1954

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

src/extra_types.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::str::FromStr;
22

33
use macaddr::{MacAddr6, MacAddr8};
44
use pyo3::{pyclass, pymethods, types::PyModule, PyAny, PyResult, Python};
5+
use geo_types::{Point, Rect, Line, LineString, Polygon};
56
use serde_json::Value;
67
use uuid::Uuid;
78

@@ -170,6 +171,108 @@ build_macaddr_type!(PyMacAddr8, MacAddr8);
170171
// pub fn new_macaddr8(value: &str) -> RustPSQLDriverPyResult<Self> {}
171172
// }
172173

174+
macro_rules! build_geo_type {
175+
($st_name:ident, $rust_type:ty) => {
176+
#[pyclass]
177+
#[derive(Clone)]
178+
pub struct $st_name {
179+
inner: $rust_type,
180+
}
181+
182+
impl $st_name {
183+
#[must_use]
184+
pub fn retrieve_value(&self) -> &$rust_type {
185+
&self.inner
186+
}
187+
}
188+
};
189+
}
190+
191+
build_geo_type!(PyPoint, Point);
192+
build_geo_type!(PyBox, Rect);
193+
build_geo_type!(PyPath, LineString);
194+
build_geo_type!(PyLine, Line);
195+
build_geo_type!(PyLineSegment, Line);
196+
build_geo_type!(PyPolygon, Polygon);
197+
// build_geo_type!(PyCircle, );
198+
199+
// #[pymethods]
200+
// impl PyPoint {
201+
// #[new]
202+
// #[allow(clippy::missing_errors_doc)]
203+
// pub fn new_point(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
204+
// Ok(Self {
205+
// inner: build_serde_value(value)?,
206+
// })
207+
// }
208+
// }
209+
210+
// #[pymethods]
211+
// impl PyBox {
212+
// #[new]
213+
// #[allow(clippy::missing_errors_doc)]
214+
// pub fn new_box(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
215+
// Ok(Self {
216+
// inner: build_serde_value(value)?,
217+
// })
218+
// }
219+
// }
220+
221+
// #[pymethods]
222+
// impl PyPath {
223+
// #[new]
224+
// #[allow(clippy::missing_errors_doc)]
225+
// pub fn new_path(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
226+
// Ok(Self {
227+
// inner: build_serde_value(value)?,
228+
// })
229+
// }
230+
// }
231+
232+
// #[pymethods]
233+
// impl PyLine {
234+
// #[new]
235+
// #[allow(clippy::missing_errors_doc)]
236+
// pub fn new_line(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
237+
// Ok(Self {
238+
// inner: build_serde_value(value)?,
239+
// })
240+
// }
241+
// }
242+
243+
// #[pymethods]
244+
// impl PyLineSegment {
245+
// #[new]
246+
// #[allow(clippy::missing_errors_doc)]
247+
// pub fn new_line_segment(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
248+
// Ok(Self {
249+
// inner: build_serde_value(value)?,
250+
// })
251+
// }
252+
// }
253+
254+
// #[pymethods]
255+
// impl PyPolygon {
256+
// #[new]
257+
// #[allow(clippy::missing_errors_doc)]
258+
// pub fn new_polygon(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
259+
// Ok(Self {
260+
// inner: build_serde_value(value)?,
261+
// })
262+
// }
263+
// }
264+
265+
// #[pymethods]
266+
// impl PyCircle {
267+
// #[new]
268+
// #[allow(clippy::missing_errors_doc)]
269+
// pub fn new_circle(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
270+
// Ok(Self {
271+
// inner: build_serde_value(value)?,
272+
// })
273+
// }
274+
// }
275+
173276
#[allow(clippy::module_name_repetitions)]
174277
#[allow(clippy::missing_errors_doc)]
175278
pub fn extra_types_module(_py: Python<'_>, pymod: &PyModule) -> PyResult<()> {
@@ -180,5 +283,12 @@ pub fn extra_types_module(_py: Python<'_>, pymod: &PyModule) -> PyResult<()> {
180283
pymod.add_class::<PyJSON>()?;
181284
pymod.add_class::<PyMacAddr6>()?;
182285
pymod.add_class::<PyMacAddr8>()?;
286+
pymod.add_class::<PyPoint>()?;
287+
pymod.add_class::<PyBox>()?;
288+
pymod.add_class::<PyPath>()?;
289+
pymod.add_class::<PyLine>()?;
290+
pymod.add_class::<PyLineSegment>()?;
291+
pymod.add_class::<PyPolygon>()?;
292+
// pymod.add_class::<PyCircle>()?;
183293
Ok(())
184294
}

0 commit comments

Comments
 (0)