summaryrefslogtreecommitdiff
path: root/src/viewmodel/vcard.rs
blob: 2d415b77bef0720d6b67cec24b0f6d12e2088ee2 (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
use yewtil::ptr::Irc;
use crate::viewmodel::telephone::Telephone;
use crate::viewmodel::address::Address;
use crate::viewmodel::name::Name;

#[derive(Clone, Debug)]
pub struct VCardData {
    pub names: Vec<Irc<Name>>,
    pub addresses: Vec<Irc<Address>>,
    pub telephones: Vec<Irc<Telephone>>,
}

macro_rules! make_vec_adder_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(),
        }
    }
    make_vec_adder_fn!( add_name names name: Irc<Name> );
    make_vec_adder_fn!( add_address addresses address: Irc<Address> );
    make_vec_adder_fn!( add_telephone telephones telephone: Irc<Telephone> );
}