From 0660151a8b641fa0a23dde2598132029970f7ae4 Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 11 Feb 2021 12:07:22 +0100 Subject: refactoring - reduced code size by about a third --- src/model/vcard.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/model/vcard.rs (limited to 'src/model/vcard.rs') diff --git a/src/model/vcard.rs b/src/model/vcard.rs new file mode 100644 index 0000000..ee7e28e --- /dev/null +++ b/src/model/vcard.rs @@ -0,0 +1,40 @@ +use crate::model::address::Address; +use crate::model::dates::Dates; +use crate::model::name::Name; +use crate::model::organizational::Organizational; +use crate::model::telephone::Telephone; + +/// Type that represents the data structure of a vcard. +#[derive(Clone, Debug)] +pub struct VCardData { + pub names: Vec, + pub addresses: Vec
, + pub telephones: Vec, + pub datess: Vec, + pub organizationals: Vec, +} + +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(), + datess: 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_dates datess => dates: Dates ); + make_vec_adder_fn!( fn add_organizational organizationals => organizational: Organizational ); +} -- cgit v1.2.3