mindat_rs/models/
common.rs

1//! Common types shared across multiple API endpoints.
2
3use serde::{Deserialize, Serialize};
4
5use super::serde_helpers::deserialize_optional_i32;
6
7/// Relation between geomaterials.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Relation {
10    /// ID of the related mineral.
11    pub mineral_id: i32,
12    /// Type of relation (1-13).
13    /// 1=Synonym, 2=Mixture, 4=Structurally related, 5=Associated at type locality,
14    /// 6=Epitaxial, 7=Polymorph, 8=Isostructural, 9=Chemically related,
15    /// 10=Common Associates, 11=Essential minerals, 12=Common ore minerals, 13=Accessory minerals
16    pub relation_type: i32,
17    /// Human-readable relation type description.
18    pub relation_type_text: String,
19}
20
21/// Statistics for a mineral.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct MinStats {
24    /// Number of photos.
25    pub ms_photos: i32,
26    /// Number of locality entries.
27    pub ms_locentries: i32,
28    /// Number of votes for photos.
29    pub ms_photovotes: i32,
30}
31
32/// GeoJSON Feature type.
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct GeoJsonFeature<P> {
35    /// Feature type (always "Feature").
36    #[serde(rename = "type")]
37    pub feature_type: String,
38    /// Feature ID.
39    pub id: Option<i32>,
40    /// Geometry data.
41    pub geometry: Option<GeoJsonGeometry>,
42    /// Feature properties.
43    pub properties: P,
44}
45
46/// GeoJSON Geometry.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(tag = "type")]
49pub enum GeoJsonGeometry {
50    Point { coordinates: Vec<f64> },
51    LineString { coordinates: Vec<Vec<f64>> },
52    Polygon { coordinates: Vec<Vec<Vec<f64>>> },
53}
54
55/// GeoJSON FeatureCollection.
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct GeoJsonFeatureCollection<P> {
58    /// Collection type (always "FeatureCollection").
59    #[serde(rename = "type")]
60    pub collection_type: String,
61    /// Features in the collection.
62    pub features: Vec<GeoJsonFeature<P>>,
63}
64
65/// Geographic region properties.
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct GeoRegionProperties {
68    /// Region text description.
69    pub lgr_revtxtd: Option<String>,
70    /// Last update time.
71    pub lgr_updttime: Option<String>,
72    /// Non-hierarchical flag.
73    #[serde(default, deserialize_with = "deserialize_optional_i32")]
74    pub lgr_non_hierarchical: Option<i32>,
75}