7676//! ]"#;
7777//!
7878//! let data: Vec<Value> = serde_json::from_str(json).unwrap();
79- //! let contact = Contact::from_vcard(&data);
79+ //! let contact = Contact::from_vcard(&data).unwrap();
80+ //!
81+ //! // use the getter functions to access the data.
82+ //! let kind = contact.kind();
83+ //! let email_addr = contact.emails().first().unwrap().email();
8084//! ```
8185
8286mod from_vcard;
@@ -249,6 +253,71 @@ impl Contact {
249253 self . postal_addresses = Some ( vec ! [ postal_address] ) ;
250254 self
251255 }
256+
257+ /// Get the langs.
258+ pub fn langs ( & self ) -> & [ Lang ] {
259+ self . langs . as_deref ( ) . unwrap_or_default ( )
260+ }
261+
262+ /// Get the kind.
263+ pub fn kind ( & self ) -> Option < & str > {
264+ self . kind . as_deref ( )
265+ }
266+
267+ /// Get the full name.
268+ pub fn full_name ( & self ) -> Option < & str > {
269+ self . full_name . as_deref ( )
270+ }
271+
272+ /// Get the name parts.
273+ pub fn name_parts ( & self ) -> Option < & NameParts > {
274+ self . name_parts . as_ref ( )
275+ }
276+
277+ /// Get the nick names.
278+ pub fn nick_names ( & self ) -> & [ String ] {
279+ self . nick_names . as_deref ( ) . unwrap_or_default ( )
280+ }
281+
282+ /// Get the titles.
283+ pub fn titles ( & self ) -> & [ String ] {
284+ self . titles . as_deref ( ) . unwrap_or_default ( )
285+ }
286+
287+ /// Get the organizational roles.
288+ pub fn roles ( & self ) -> & [ String ] {
289+ self . roles . as_deref ( ) . unwrap_or_default ( )
290+ }
291+
292+ /// Get the organizational names.
293+ pub fn organizational_names ( & self ) -> & [ String ] {
294+ self . organization_names . as_deref ( ) . unwrap_or_default ( )
295+ }
296+
297+ /// Get the postal addresses.
298+ pub fn postal_addresses ( & self ) -> & [ PostalAddress ] {
299+ self . postal_addresses . as_deref ( ) . unwrap_or_default ( )
300+ }
301+
302+ /// Get the emails.
303+ pub fn emails ( & self ) -> & [ Email ] {
304+ self . emails . as_deref ( ) . unwrap_or_default ( )
305+ }
306+
307+ /// Get the phones.
308+ pub fn phones ( & self ) -> & [ Phone ] {
309+ self . phones . as_deref ( ) . unwrap_or_default ( )
310+ }
311+
312+ /// Get the contact uris.
313+ pub fn contact_uris ( & self ) -> & [ String ] {
314+ self . contact_uris . as_deref ( ) . unwrap_or_default ( )
315+ }
316+
317+ /// Get the URLs.
318+ pub fn urls ( & self ) -> & [ String ] {
319+ self . urls . as_deref ( ) . unwrap_or_default ( )
320+ }
252321}
253322
254323/// The language preference of the contact.
@@ -261,6 +330,18 @@ pub struct Lang {
261330 pub tag : String ,
262331}
263332
333+ impl Lang {
334+ /// Get the preference.
335+ pub fn preference ( & self ) -> Option < u64 > {
336+ self . preference
337+ }
338+
339+ /// Get the RFC 5646 language tag.
340+ pub fn tag ( & self ) -> & str {
341+ self . tag . as_str ( )
342+ }
343+ }
344+
264345impl Display for Lang {
265346 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
266347 if let Some ( pref) = self . preference {
@@ -308,6 +389,31 @@ impl NameParts {
308389 suffixes : to_opt_vec ( suffixes) ,
309390 }
310391 }
392+
393+ /// Get the name prefixes.
394+ pub fn prefixes ( & self ) -> & [ String ] {
395+ self . prefixes . as_deref ( ) . unwrap_or_default ( )
396+ }
397+
398+ /// Get the sur names.
399+ pub fn surnames ( & self ) -> & [ String ] {
400+ self . surnames . as_deref ( ) . unwrap_or_default ( )
401+ }
402+
403+ /// Get the middle names.
404+ pub fn middle_names ( & self ) -> & [ String ] {
405+ self . middle_names . as_deref ( ) . unwrap_or_default ( )
406+ }
407+
408+ /// Get the given names.
409+ pub fn given_names ( & self ) -> & [ String ] {
410+ self . given_names . as_deref ( ) . unwrap_or_default ( )
411+ }
412+
413+ /// Get the suffixes.
414+ pub fn suffixes ( & self ) -> & [ String ] {
415+ self . suffixes . as_deref ( ) . unwrap_or_default ( )
416+ }
311417}
312418
313419/// A postal address.
@@ -382,6 +488,68 @@ impl PostalAddress {
382488 postal_code,
383489 }
384490 }
491+
492+ /// Get the preference.
493+ pub fn preference ( & self ) -> Option < u64 > {
494+ self . preference
495+ }
496+
497+ /// Get the contexts.
498+ pub fn contexts ( & self ) -> & [ String ] {
499+ self . contexts . as_deref ( ) . unwrap_or_default ( )
500+ }
501+
502+ /// Get the full address.
503+ ///
504+ /// An unstructured address. An unstructured postal address is
505+ /// usually the complete postal address. That is, this string
506+ /// would contain the street address, country, region, postal code, etc...
507+ ///
508+ /// Depending on how the postal address is given, it can either
509+ /// be structured or unstructured. If it is given as unstructured,
510+ /// then this value is populated.
511+ ///
512+ /// It is possible that a single postal address is given as both,
513+ /// in which case this value is populated along with the other
514+ /// values of the postal address.
515+ pub fn full_address ( & self ) -> Option < & str > {
516+ self . full_address . as_deref ( )
517+ }
518+
519+ /// Get the street parts.
520+ pub fn street_parts ( & self ) -> & [ String ] {
521+ self . street_parts . as_deref ( ) . unwrap_or_default ( )
522+ }
523+
524+ /// Get the locality.
525+ pub fn locality ( & self ) -> Option < & str > {
526+ self . locality . as_deref ( )
527+ }
528+
529+ /// Get the region name.
530+ pub fn region_name ( & self ) -> Option < & str > {
531+ self . region_name . as_deref ( )
532+ }
533+
534+ /// Get the region code.
535+ pub fn region_code ( & self ) -> Option < & str > {
536+ self . region_code . as_deref ( )
537+ }
538+
539+ /// Get the country name.
540+ pub fn country_name ( & self ) -> Option < & str > {
541+ self . country_name . as_deref ( )
542+ }
543+
544+ /// Get the country code.
545+ pub fn country_code ( & self ) -> Option < & str > {
546+ self . country_code . as_deref ( )
547+ }
548+
549+ /// Get the postal code.
550+ pub fn postal_code ( & self ) -> Option < & str > {
551+ self . postal_code . as_deref ( )
552+ }
385553}
386554
387555/// Represents an email address.
@@ -407,6 +575,21 @@ impl Email {
407575 email,
408576 }
409577 }
578+
579+ /// Get the preference.
580+ pub fn preference ( & self ) -> Option < u64 > {
581+ self . preference
582+ }
583+
584+ /// Get the contexts.
585+ pub fn contexts ( & self ) -> & [ String ] {
586+ self . contexts . as_deref ( ) . unwrap_or_default ( )
587+ }
588+
589+ /// Get the email address.
590+ pub fn email ( & self ) -> & str {
591+ self . email . as_str ( )
592+ }
410593}
411594
412595impl Display for Email {
@@ -459,6 +642,26 @@ impl Phone {
459642 features : to_opt_vec ( features) ,
460643 }
461644 }
645+
646+ /// Get the preference.
647+ pub fn preference ( & self ) -> Option < u64 > {
648+ self . preference
649+ }
650+
651+ /// Get the contexts.
652+ pub fn contexts ( & self ) -> & [ String ] {
653+ self . contexts . as_deref ( ) . unwrap_or_default ( )
654+ }
655+
656+ /// Get the phone number.
657+ pub fn phone ( & self ) -> & str {
658+ self . phone . as_str ( )
659+ }
660+
661+ /// Get the phone features.
662+ pub fn features ( & self ) -> & [ String ] {
663+ self . features . as_deref ( ) . unwrap_or_default ( )
664+ }
462665}
463666
464667impl Display for Phone {
0 commit comments