1use std::fmt::{self, Display, Formatter, Write};
2
3use validators::{Validated, ValidatedWrapper};
4
5use super::{
6 super::{
7 parameters::{
8 alternative_id::AlternativeID, any::Any, media_type::MediaType, preference::Preference,
9 property_id::PropertyID, typ::Type, Parameter,
10 },
11 values::{geo_value::GeoValue, Value},
12 Set,
13 },
14 *,
15};
16
17#[derive(Clone, Debug, PartialEq, Eq, Hash)]
18pub struct Geo {
19 pub typ: Option<Type>,
20 pub media_type: Option<MediaType>,
21 pub property_id: Option<PropertyID>,
22 pub preference: Option<Preference>,
23 pub alternative_id: Option<AlternativeID>,
24 pub any: Option<Set<Any>>,
25 pub value: GeoValue,
26}
27
28impl Geo {
29 pub fn from_geo_value(geo_value: GeoValue) -> Geo {
30 Geo {
31 typ: None,
32 media_type: None,
33
34 property_id: None,
35 preference: None,
36 alternative_id: None,
37 any: None,
38 value: geo_value,
39 }
40 }
41}
42
43impl Property for Geo {
44 fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
45 f.write_str("GEO")?;
46
47 macro_rules! fmt {
48 ($c:tt, $p:ident) => {
49 fmt_g!($c, Parameter, self, $p, f);
50 };
51 }
52
53 fmt!(0, typ);
54 fmt!(0, media_type);
55 fmt!(0, property_id);
56 fmt!(0, preference);
57 fmt!(0, alternative_id);
58 fmt!(2, any);
59
60 f.write_char(':')?;
61
62 Value::fmt(&self.value, f)?;
63
64 f.write_str("\r\n")?;
65
66 Ok(())
67 }
68}
69
70impl Display for Geo {
71 fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
72 Property::fmt(self, f)
73 }
74}
75
76impl Validated for Geo {}
77
78impl ValidatedWrapper for Geo {
79 type Error = &'static str;
80
81 fn from_string(_from_string_input: String) -> Result<Self, Self::Error> {
82 unimplemented!();
83 }
84
85 fn from_str(_from_str_input: &str) -> Result<Self, Self::Error> {
86 unimplemented!();
87 }
88}