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
use super::Set;

use std::collections::HashSet;
use std::fmt::{self, Formatter, Write};
use std::hash::Hash;
use validators::ValidatedWrapper;

pub mod address_value;
pub mod attribute_value;
pub mod audio_value;
pub mod boolean;
pub mod calscale_value;
pub mod client_property_id_map_value;
pub mod date_time;
pub mod email_value;
pub mod float;
pub mod gender_value;
pub mod geo_value;
pub mod image_value;
pub mod integer;
pub mod key_value;
pub mod kind_value;
pub mod language_tag;
pub mod name_value;
pub mod parameter_value;
pub mod preference_value;
pub mod product_id_value;
pub mod property_id_value;
pub mod telephone_value;
pub mod text;
pub mod time_zone_value;
pub mod type_value;
pub mod uid_value;
pub mod uri;
pub mod url;
pub mod uuid;
pub mod value_type;
pub mod version_value;

pub trait Value {
    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error>;
}

impl<V: Value + ValidatedWrapper + Eq + Hash> Value for Set<V> {
    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        let v: &HashSet<V> = self.as_hash_set();

        for e in v.iter().take(1) {
            Value::fmt(e, f)?;
        }

        for e in v.iter().skip(1) {
            f.write_char(',')?;
            Value::fmt(e, f)?;
        }

        Ok(())
    }
}