mindat-rs 0.2.0

A Rust client library for the Mindat API - access mineralogical data including geomaterials, localities, and IMA minerals
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
//! Locality types for the Mindat API.

use serde::{Deserialize, Serialize};

use super::serde_helpers::{
    deserialize_i64, deserialize_optional_f64, deserialize_optional_i16, deserialize_optional_i32,
    deserialize_optional_vec_i32,
};

/// A locality from the Mindat database.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Locality {
    /// Mindat ID.
    pub id: i32,
    /// Long ID string.
    #[serde(default)]
    pub longid: Option<String>,
    /// GUID.
    #[serde(default)]
    pub guid: Option<String>,
    /// Locality text/name.
    #[serde(default)]
    pub txt: Option<String>,
    /// Reversed text description.
    #[serde(default)]
    pub revtxtd: Option<String>,
    /// Short description.
    #[serde(default)]
    pub description_short: Option<String>,
    /// Latitude.
    #[serde(default, deserialize_with = "deserialize_optional_f64")]
    pub latitude: Option<f64>,
    /// Longitude.
    #[serde(default, deserialize_with = "deserialize_optional_f64")]
    pub longitude: Option<f64>,
    /// Language-specific text.
    #[serde(default)]
    pub langtxt: Option<String>,
    /// Date added.
    #[serde(default)]
    pub dateadd: Option<String>,
    /// Date modified.
    #[serde(default)]
    pub datemodify: Option<String>,
    /// Elements found at this locality.
    #[serde(default)]
    pub elements: Option<String>,
    /// Country name.
    #[serde(default)]
    pub country: Option<String>,
    /// References.
    #[serde(default)]
    pub refs: Option<String>,
    /// Coordinate system.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub coordsystem: Option<i32>,
    /// Parent locality ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub parent: Option<i32>,
    /// Links.
    #[serde(default)]
    pub links: Option<String>,
    /// Area.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub area: Option<i32>,
    /// Non-hierarchical flag.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub non_hierarchical: Option<i32>,
    /// Age ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub age: Option<i32>,
    /// Meteorite type.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub meteorite_type: Option<i32>,
    /// Company ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub company: Option<i32>,
    /// Company 2 ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub company2: Option<i32>,
    /// Locality status ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub loc_status: Option<i32>,
    /// Locality group.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub loc_group: Option<i32>,
    /// Status year.
    #[serde(default)]
    pub status_year: Option<String>,
    /// Company year.
    #[serde(default)]
    pub company_year: Option<String>,
    /// Discovered before.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub discovered_before: Option<i32>,
    /// Discovery year.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub discovery_year: Option<i32>,
    /// Discovery year type.
    #[serde(default)]
    pub discovery_year_type: Option<String>,
    /// Hierarchy level.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub level: Option<i32>,
    /// Included localities.
    #[serde(default)]
    pub locsinclude: Option<String>,
    /// Excluded localities.
    #[serde(default)]
    pub locsexclude: Option<String>,
    /// Wikipedia link.
    #[serde(default)]
    pub wikipedia: Option<String>,
    /// OSM ID.
    #[serde(default)]
    pub osmid: Option<String>,
    /// Geonames ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub geonames: Option<i32>,
    /// Timestamp.
    #[serde(default)]
    pub timestamp: Option<String>,
    /// Geomaterials at this locality (when expanded).
    #[serde(default, deserialize_with = "deserialize_optional_vec_i32")]
    pub geomaterials: Option<Vec<i32>>,
}

/// Builder for locality query parameters.
#[derive(Debug, Clone, Default)]
pub struct LocalitiesQuery {
    /// Country name filter.
    pub country: Option<String>,
    /// Locality name contains.
    pub txt: Option<String>,
    /// Description contains.
    pub description: Option<String>,
    /// Include elements (comma-separated).
    pub elements_inc: Option<String>,
    /// Exclude elements (comma-separated).
    pub elements_exc: Option<String>,
    /// Filter by IDs.
    pub id_in: Option<Vec<i32>>,
    /// Only localities at or above this hierarchy level.
    pub level_gte: Option<i32>,
    /// Only localities at or below this hierarchy level.
    pub level_lte: Option<i32>,
    /// Only localities with at least this many sub-localities.
    pub sublocs_gte: Option<i32>,
    /// Only localities with at most this many sub-localities.
    pub sublocs_lte: Option<i32>,
    /// Filter by non-hierarchical flag.
    pub non_hierarchial: Option<i32>,
    /// Description text starts with (case-insensitive).
    pub revtxtd_istartswith: Option<String>,
    /// Updated after datetime.
    pub updated_at: Option<String>,
    /// Fields to include.
    pub fields: Option<String>,
    /// Fields to omit.
    pub omit: Option<String>,
    /// Fields to expand.
    pub expand: Option<Vec<String>>,
    /// Page size (number of results per page).
    pub page_size: Option<i32>,
    /// Page number for pagination.
    pub page: Option<i32>,
}

impl LocalitiesQuery {
    /// Create a new empty query.
    pub fn new() -> Self {
        Self::default()
    }

    /// Filter by country name.
    pub fn country(mut self, country: impl Into<String>) -> Self {
        self.country = Some(country.into());
        self
    }

    /// Filter by locality name.
    pub fn name_contains(mut self, txt: impl Into<String>) -> Self {
        self.txt = Some(txt.into());
        self
    }

    /// Filter by description.
    pub fn description_contains(mut self, desc: impl Into<String>) -> Self {
        self.description = Some(desc.into());
        self
    }

    /// Filter by included elements.
    pub fn with_elements(mut self, elements: impl Into<String>) -> Self {
        self.elements_inc = Some(elements.into());
        self
    }

    /// Filter by excluded elements.
    pub fn without_elements(mut self, elements: impl Into<String>) -> Self {
        self.elements_exc = Some(elements.into());
        self
    }

    /// Select specific fields.
    pub fn select_fields(mut self, fields: impl Into<String>) -> Self {
        self.fields = Some(fields.into());
        self
    }

    /// Omit specific fields.
    pub fn omit_fields(mut self, fields: impl Into<String>) -> Self {
        self.omit = Some(fields.into());
        self
    }

    /// Expand related fields.
    pub fn expand_fields(mut self, fields: Vec<String>) -> Self {
        self.expand = Some(fields);
        self
    }

    /// Filter by hierarchy level range (inclusive).
    pub fn level_range(mut self, min: i32, max: i32) -> Self {
        self.level_gte = Some(min);
        self.level_lte = Some(max);
        self
    }

    /// Set page size (number of results per page).
    pub fn page_size(mut self, size: i32) -> Self {
        self.page_size = Some(size);
        self
    }

    /// Set page number for pagination.
    pub fn page(mut self, page: i32) -> Self {
        self.page = Some(page);
        self
    }
}

/// Locality age information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LocalityAge {
    /// Age ID.
    pub age_id: i32,
    /// Age MA value.
    #[serde(default, deserialize_with = "deserialize_optional_f64")]
    pub age_mav: Option<f64>,
    /// Age PM value.
    #[serde(default, deserialize_with = "deserialize_optional_f64")]
    pub age_pmv: Option<f64>,
    /// Age MA2 value.
    #[serde(default, deserialize_with = "deserialize_optional_f64")]
    pub age_ma2v: Option<f64>,
    /// Age PM2 value.
    #[serde(default, deserialize_with = "deserialize_optional_f64")]
    pub age_pm2v: Option<f64>,
    /// Age method.
    #[serde(default)]
    pub agemethod: Option<String>,
    /// Age reference.
    #[serde(default)]
    pub agereference: Option<String>,
    /// Age MA string.
    #[serde(default)]
    pub age_ma: Option<String>,
    /// Age PM string.
    #[serde(default)]
    pub age_pm: Option<String>,
    /// Age MA2 string.
    #[serde(default)]
    pub age_ma2: Option<String>,
    /// Age PM2 string.
    #[serde(default)]
    pub age_pm2: Option<String>,
    /// Ages 1.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub ages1: Option<i32>,
    /// Ages 2.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub ages2: Option<i32>,
    /// Age type.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub age_type: Option<i32>,
}

/// Locality status information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LocalityStatus {
    /// Status ID.
    pub ls_id: i32,
    /// Status text.
    pub ls_text: String,
    /// Historical flag.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub ls_historical: Option<i32>,
    /// Wide flag.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub ls_wide: Option<i32>,
}

/// Locality type information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LocalityType {
    /// Type ID.
    pub lt_id: i32,
    /// Type text.
    pub lt_text: String,
    /// Parent type ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub lt_parent: Option<i32>,
    /// Sort order.
    #[serde(default, deserialize_with = "deserialize_optional_i16")]
    pub lt_sortorder: Option<i16>,
    /// Erratic flag.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub lt_erratic: Option<i32>,
    /// Area flag.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub lt_area: Option<i32>,
    /// Underground flag.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub lt_underground: Option<i32>,
}

/// A translated locality name (`/locality-translations/`).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LocalityTranslation {
    /// Translation ID.
    #[serde(deserialize_with = "deserialize_i64")]
    pub lt_id: i64,
    /// Locality ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub lt_loc: Option<i32>,
    /// Translated text.
    #[serde(default)]
    pub lt_text: Option<String>,
    /// Translation datetime.
    #[serde(default)]
    pub lt_datetime: Option<String>,
    /// Contributing user ID.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub lt_uid: Option<i32>,
    /// ISO language code.
    #[serde(default)]
    pub lt_iso: Option<String>,
    /// Important flag.
    #[serde(default, deserialize_with = "deserialize_optional_i32")]
    pub lt_important: Option<i32>,
}

/// Builder for `/locality-translations/` query parameters.
#[derive(Debug, Clone, Default)]
pub struct LocalityTranslationsQuery {
    /// Filter by locality ID.
    pub lt_loc: Option<i32>,
    /// Filter by ISO language code.
    pub lt_iso: Option<String>,
    /// Filter by translated text.
    pub lt_text: Option<String>,
    /// Filter by important flag.
    pub lt_important: Option<i32>,
    /// Modified at/after datetime.
    pub lt_datetime_gte: Option<String>,
    /// Ordering field.
    pub ordering: Option<String>,
    /// Page number.
    pub page: Option<i32>,
    /// Page size.
    pub page_size: Option<i32>,
}

impl LocalityTranslationsQuery {
    /// Create a new empty query.
    pub fn new() -> Self {
        Self::default()
    }

    /// Filter to translations for a given locality.
    pub fn locality(mut self, locality_id: i32) -> Self {
        self.lt_loc = Some(locality_id);
        self
    }

    /// Filter by ISO language code.
    pub fn language(mut self, iso: impl Into<String>) -> Self {
        self.lt_iso = Some(iso.into());
        self
    }

    /// Set page number.
    pub fn page(mut self, page: i32) -> Self {
        self.page = Some(page);
        self
    }

    /// Set page size.
    pub fn page_size(mut self, size: i32) -> Self {
        self.page_size = Some(size);
        self
    }
}