parse_rs/
geopoint.rs

1// src/geopoint.rs
2
3use serde::{Deserialize, Serialize};
4
5/// Represents a geographical point.
6#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
7pub struct ParseGeoPoint {
8    #[serde(rename = "__type")]
9    type_field: String, // Should always be "GeoPoint"
10    pub latitude: f64,
11    pub longitude: f64,
12}
13
14impl ParseGeoPoint {
15    /// Creates a new `ParseGeoPoint`.
16    ///
17    /// # Panics
18    /// Panics if latitude is not between -90 and 90, or longitude is not between -180 and 180.
19    pub fn new(latitude: f64, longitude: f64) -> Self {
20        if !(-90.0..=90.0).contains(&latitude) {
21            panic!("Latitude must be between -90 and 90 degrees.");
22        }
23        if !(-180.0..=180.0).contains(&longitude) {
24            panic!("Longitude must be between -180 and 180 degrees.");
25        }
26        ParseGeoPoint {
27            type_field: "GeoPoint".to_string(),
28            latitude,
29            longitude,
30        }
31    }
32}