use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(test, derive(Default))]
pub struct Locale {
#[serde(rename = "ip")]
pub ip: String,
#[serde(rename = "countryCode")]
pub country_code: String,
#[serde(rename = "country")]
pub country: String,
#[serde(rename = "continentCode")]
pub continent_code: String,
#[serde(rename = "continent")]
pub continent: String,
#[serde(rename = "eu")]
pub eu: bool,
#[serde(rename = "currency")]
pub currency: String,
#[serde(rename = "city")]
#[serde(skip_serializing_if = "Option::is_none")]
pub city: Option<String>,
#[serde(rename = "timeZone")]
#[serde(skip_serializing_if = "Option::is_none")]
pub time_zone: Option<String>,
#[serde(rename = "postalCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub postal_code: Option<String>,
#[serde(rename = "latitude")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latitude: Option<f64>,
#[serde(rename = "longitude")]
#[serde(skip_serializing_if = "Option::is_none")]
pub longitude: Option<f64>,
#[serde(rename = "autonomousSystemNumber")]
#[serde(skip_serializing_if = "Option::is_none")]
pub autonomous_system_number: Option<String>,
#[serde(rename = "autonomousSystemOrganization")]
#[serde(skip_serializing_if = "Option::is_none")]
pub autonomous_system_organization: Option<String>,
#[serde(rename = "isp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub isp: Option<String>,
#[serde(rename = "connectionType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub connection_type: Option<String>,
#[serde(rename = "connectionUsageType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub connection_usage_type: Option<String>,
#[serde(rename = "connectionOrganization")]
#[serde(skip_serializing_if = "Option::is_none")]
pub connection_organization: Option<String>,
}
impl Locale {
pub fn ip(&self) -> &String {
&self.ip
}
pub fn country_code(&self) -> &String {
&self.country_code
}
pub fn country(&self) -> &String {
&self.country
}
pub fn continent_code(&self) -> &String {
&self.continent_code
}
pub fn continent(&self) -> &String {
&self.continent
}
pub fn eu(&self) -> &bool {
&self.eu
}
pub fn currency(&self) -> &String {
&self.currency
}
pub fn set_city(mut self, city: String) -> Self {
self.city = Some(city);
self
}
pub fn city(&self) -> Option<&String> {
self.city.as_ref()
}
pub fn set_time_zone(mut self, time_zone: String) -> Self {
self.time_zone = Some(time_zone);
self
}
pub fn time_zone(&self) -> Option<&String> {
self.time_zone.as_ref()
}
pub fn set_postal_code(mut self, postal_code: String) -> Self {
self.postal_code = Some(postal_code);
self
}
pub fn postal_code(&self) -> Option<&String> {
self.postal_code.as_ref()
}
pub fn set_latitude(mut self, latitude: f64) -> Self {
self.latitude = Some(latitude);
self
}
pub fn latitude(&self) -> Option<&f64> {
self.latitude.as_ref()
}
pub fn set_longitude(mut self, longitude: f64) -> Self {
self.longitude = Some(longitude);
self
}
pub fn longitude(&self) -> Option<&f64> {
self.longitude.as_ref()
}
pub fn set_autonomous_system_number(mut self, autonomous_system_number: String) -> Self {
self.autonomous_system_number = Some(autonomous_system_number);
self
}
pub fn autonomous_system_number(&self) -> Option<&String> {
self.autonomous_system_number.as_ref()
}
pub fn set_autonomous_system_organization(mut self, autonomous_system_organization: String) -> Self {
self.autonomous_system_organization = Some(autonomous_system_organization);
self
}
pub fn autonomous_system_organization(&self) -> Option<&String> {
self.autonomous_system_organization.as_ref()
}
pub fn set_isp(mut self, isp: String) -> Self {
self.isp = Some(isp);
self
}
pub fn isp(&self) -> Option<&String> {
self.isp.as_ref()
}
pub fn set_connection_type(mut self, connection_type: String) -> Self {
self.connection_type = Some(connection_type);
self
}
pub fn connection_type(&self) -> Option<&String> {
self.connection_type.as_ref()
}
pub fn set_connection_usage_type(mut self, connection_usage_type: String) -> Self {
self.connection_usage_type = Some(connection_usage_type);
self
}
pub fn connection_usage_type(&self) -> Option<&String> {
self.connection_usage_type.as_ref()
}
pub fn set_connection_organization(mut self, connection_organization: String) -> Self {
self.connection_organization = Some(connection_organization);
self
}
pub fn connection_organization(&self) -> Option<&String> {
self.connection_organization.as_ref()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_locale_creation() {
let _model = <Locale as Default>::default();
let _ = _model.ip();
let _ = _model.country_code();
let _ = _model.country();
let _ = _model.continent_code();
let _ = _model.continent();
let _ = _model.eu();
let _ = _model.currency();
}
#[test]
fn test_locale_serialization() {
let model = <Locale as Default>::default();
let json = serde_json::to_string(&model);
assert!(json.is_ok());
let deserialized: Result<Locale, _> = serde_json::from_str(&json.unwrap());
assert!(deserialized.is_ok());
}
}