summaryrefslogtreecommitdiff
path: root/src/model/vcard.rs
blob: 4670fe7c329b22e0c6b4e34691d4f13032c4e36e (plain)
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
use crate::model::property_groups::address::Address;
use crate::model::property_groups::communication::Communication;
use crate::model::property_groups::name::Name;
use crate::model::property_groups::organizational::Organizational;
use crate::model::property_groups::other_identification::OtherIdentification;
use crate::model::property_groups::telephone::Telephone;

/// Type that represents the data structure of a vcard.
#[derive(Clone, Debug)]
pub struct VCardData {
    pub names: Vec<Name>,
    pub addresses: Vec<Address>,
    pub telephones: Vec<Telephone>,
    pub communications: Vec<Communication>,
    pub other_identifications: Vec<OtherIdentification>,
    pub organizationals: Vec<Organizational>,
}

macro_rules! make_vec_adder_fn {
    ( fn $fnname:ident $property:ident => $($arg_name:ident : $arg_type:ty),* ) => {
        pub fn $fnname(&mut self, $( $arg_name : $arg_type ),*) {
            $(self.$property.push($arg_name);)*
        }
    };
}

impl VCardData {
    pub fn new() -> Self {
        Self {
            names: Vec::new(),
            addresses: Vec::new(),
            telephones: Vec::new(),
            communications: Vec::new(),
            other_identifications: Vec::new(),
            organizationals: Vec::new(),
        }
    }
    make_vec_adder_fn!( fn add_name names => name: Name );
    make_vec_adder_fn!( fn add_address addresses => address: Address );
    make_vec_adder_fn!( fn add_telephone telephones => telephone: Telephone );
    make_vec_adder_fn!( fn add_communication communications => communication: Communication );
    make_vec_adder_fn!( fn add_other_identification other_identifications => other_identification: OtherIdentification );
    make_vec_adder_fn!( fn add_organizational organizationals => organizational: Organizational );
}