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
use serde::Deserialize; use crate::CommonProperties; #[derive(Deserialize)] pub struct Coordinates { pub latitude: f64, pub longitude: f64, #[serde(default)] pub precision: Option<f64>, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Region(String); #[derive(Debug, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Country(String); #[derive(Deserialize, stix_derive::TypedObject)] #[typed_object(core)] pub struct Location { #[serde(flatten)] base: CommonProperties, pub name: String, #[serde(default)] pub description: Option<String>, #[serde(default)] pub region: Option<Region>, #[serde(default)] pub country: Option<Country>, #[serde(default)] pub administrative_area: Option<String>, #[serde(default)] pub city: Option<String>, #[serde(default)] pub street_address: Option<String>, #[serde(default)] pub postal_code: Option<String>, #[serde(default, flatten)] coordinates: Option<Coordinates>, } impl Location { pub fn name(&self) -> &str { &self.name } pub fn description(&self) -> Option<&str> { self.description.as_ref().map(|s| s.as_str()) } pub fn coordinates(&self) -> Option<&Coordinates> { self.coordinates.as_ref() } } impl AsRef<CommonProperties> for Location { fn as_ref(&self) -> &CommonProperties { &self.base } }