Skip to main content

Crate vcard

Crate vcard 

Source
Expand description

§vCard

A pure Rust implementation of vCard 4.0 for generating and parsing vCards, based on RFC 6350 and RFC 9554.

§Generating a vCard

Create a VCard and fill its public fields, then serialize it with to_string or VCard::save_to_file.

use vcard::{
    VCard,
    values::{NameValue, TelValue},
    Name, Tel, TypeValue,
};

let mut vcard = VCard::new("David Wang");

let mut name = Name::new(NameValue {
    family_names: vec![String::from("Wang")],
    given_names: vec![String::from("David")],
    ..NameValue::default()
});

vcard.names.push(name);

let mut telephone = Tel::new(TelValue::Text(String::from("+886-912-345-678")));

telephone.parameters.types.push(TypeValue::Cell);

vcard.telephones.push(telephone);

assert_eq!(
    "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:David Wang\r\nN:Wang;David;;;\r\nTEL;TYPE=cell:+886-912-345-678\r\nEND:VCARD\r\n",
    vcard.to_string()
);

§Parsing vCards

Parse a single vCard with str::parse or several of them with VCard::parse_multiple.

use vcard::VCard;

let vcard: VCard = "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Magic Len\r\nEND:VCARD\r\n".parse().unwrap();

assert_eq!("Magic Len", vcard.formatted_names[0].value);

Re-exports§

pub use base64;
pub use chrono;
pub use chrono_tz;
pub use mime;
pub use mime_guess;
pub use oxilangtag;
pub use url;
pub use validators;

Modules§

values
Value types used by vCard properties, defined in RFC 6350 section 4 and extended by RFC 9554.

Structs§

AnyParameter
An extension parameter that this crate has no dedicated field for.
ExtensionProperty
A property that this crate has no dedicated field for, which is an x-name or IANA extension property.
FoldingWriter
A writer that folds long content lines by inserting a CRLF followed by a single space.
GroupName
The group name that can prefix a property, e.g. the item1 of item1.TEL:....
InvalidValueError
The error type for a value that does not match the format expected by its type.
Parameters
The parameters of a property.
ParseError
The error type produced when parsing vCard text fails.
Pid
The value of the PID parameter, e.g. 1 or 3.1.
Pref
The value of the PREF parameter, an integer between 1 and 100 where lower means more preferred.
PropId
The value of the PROP-ID parameter defined by RFC 9554, which identifies a property among its siblings.
Property
A single vCard property with an optional group, parameters and a typed value.
Script
The value of the SCRIPT parameter defined by RFC 9554, which is a script subtag like Latn.
VCard
A vCard as defined by RFC 6350 and extended by RFC 9554.

Enums§

Calscale
The value of the CALSCALE parameter, which describes the calendar system of a date.
ParseErrorKind
The reasons why parsing vCard text can fail.
Phonetic
The value of the PHONETIC parameter defined by RFC 9554, which names a phonetic system.
TypeValue
A value of the TYPE parameter.
TzParam
The value of the TZ parameter, which is a time zone text or a URI.
ValidationError
The error type returned by VCard::validate.

Traits§

PropertyValue
The behavior that a type must provide to work as the value of a property.

Type Aliases§

Address
The ADR property, which holds the structured delivery address components.
Anniversary
The ANNIVERSARY property, which is the anniversary date of the represented entity.
Birthday
The BDAY property, which is the birth date of the represented entity.
CalendarAddressUri
The CALADRURI property, which is a URI for scheduling calendar requests.
CalendarUri
The CALURI property, which is a URI of the calendar of the represented entity.
Categories
The CATEGORIES property, which holds tags that can be used for filtering.
ClientPidMap
The CLIENTPIDMAP property, which maps PID source numbers to globally unique URIs.
Created
The CREATED property defined by RFC 9554, which is the timestamp when the vCard was created.
Email
The EMAIL property, which is an email address.
Fburl
The FBURL property, which is a URI of the free-busy time information.
FormattedName
The FN property, which is the formatted name of the represented entity.
Gender
The GENDER property, which holds the sex and the gender identity components.
Geo
The GEO property, which is a URI with the geographic position of the represented entity.
GramGender
The GRAMGENDER property defined by RFC 9554, which is the grammatical gender to use in salutations.
Impp
The IMPP property, which is a URI for instant messaging or presence.
Key
The KEY property, which is a public key or certificate as a URI or text.
Kind
The KIND property, which describes what the vCard represents.
Lang
The LANG property, which is a language that the represented entity can use.
Language
The LANGUAGE property defined by RFC 9554, which is the default language of the text values in the vCard.
Logo
The LOGO property, which is a URI pointing to or embedding a logo image.
Member
The MEMBER property, which is a URI of a member of the group that the vCard represents.
Name
The N property, which holds the structured name components.
Nickname
The NICKNAME property, which holds one or more nicknames.
Note
The NOTE property, which is a free-form comment.
Org
The ORG property, which holds the organization name and unit names.
Photo
The PHOTO property, which is a URI pointing to or embedding an image of the represented entity.
ProdId
The PRODID property, which identifies the product that created the vCard.
Pronouns
The PRONOUNS property defined by RFC 9554, which holds the pronouns of the represented entity.
Related
The RELATED property, which is a URI or text describing a related entity.
Rev
The REV property, which is the timestamp of the last change of the vCard.
Role
The ROLE property, which is the function of the represented entity.
SocialProfile
The SOCIALPROFILE property defined by RFC 9554, which is a social media profile as a URI or a username text.
Sound
The SOUND property, which is a URI pointing to or embedding a sound, e.g. the name pronunciation.
Source
The SOURCE property, which is a URI where the newest version of this vCard can be fetched.
Tel
The TEL property, which is a telephone number as a URI or text.
TimeZone
The TZ property, which is the time zone of the represented entity.
Title
The TITLE property, which is the position or job of the represented entity.
Uid
The UID property, which is a globally unique identifier of the vCard, usually a urn:uuid: URI.
Url
The URL property, which is a website URI associated with the represented entity.
Xml
The XML property, which carries an extended XML-encoded element.