vcard/values/
mod.rs

1use std::{
2    collections::HashSet,
3    fmt::{self, Formatter, Write},
4    hash::Hash,
5};
6
7use validators::ValidatedWrapper;
8
9use super::Set;
10
11pub mod address_value;
12pub mod attribute_value;
13pub mod audio_value;
14pub mod boolean;
15pub mod calscale_value;
16pub mod client_property_id_map_value;
17pub mod date_time;
18pub mod email_value;
19pub mod float;
20pub mod gender_value;
21pub mod geo_value;
22pub mod image_value;
23pub mod integer;
24pub mod key_value;
25pub mod kind_value;
26pub mod language_tag;
27pub mod name_value;
28pub mod parameter_value;
29pub mod preference_value;
30pub mod product_id_value;
31pub mod property_id_value;
32pub mod telephone_value;
33pub mod text;
34pub mod time_zone_value;
35pub mod type_value;
36pub mod uid_value;
37pub mod uri;
38pub mod url;
39pub mod uuid;
40pub mod value_type;
41pub mod version_value;
42
43pub trait Value {
44    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error>;
45}
46
47impl<V: Value + ValidatedWrapper + Eq + Hash> Value for Set<V> {
48    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
49        let v: &HashSet<V> = self.as_hash_set();
50
51        for e in v.iter().take(1) {
52            Value::fmt(e, f)?;
53        }
54
55        for e in v.iter().skip(1) {
56            f.write_char(',')?;
57            Value::fmt(e, f)?;
58        }
59
60        Ok(())
61    }
62}