vCard Parser

Parses and validates vCard data according to RFC 6350 specification.

rust crates license release

Installation

Add the library to the dependencies section of your cargo.toml file.

toml [dependencies] vcard_parser = "0.1.2"

Usage

Rust documentation is here. There are two main functions for parsing vCards from a file or input string:

Typically, you will use parsetovcardswithouterrors, unless you are sure that the input doesn't contain x-param or iana-token properties.

Parsing vCards

Reading a vcf file, updating the vCard object, and writing back to the file.

```rust use std::fs; use std::fs::readtostring; use vcardparser::parsetovcardswithouterrors; use vcardparser::vcard::property::types::PropertyType;

fn main () { if let Ok(string) = readtostring("contacts.vcf") { let mut vcards = parsetovcardswithouterrors(string.as_str());

    let mut vcard = vcards.first().unwrap().clone();
    let property = vcard.get_property_by_type(&PropertyType::Fn).unwrap();

    vcard.update_property(property.get_uuid(), "FN:John Doe").expect("Unable to update property.");
    vcards[0] = vcard;

    let mut data = String::new();
    for vcard in vcards {
        data.push_str(vcard.to_string().as_str())
    }
    fs::write("contacts.vcf", data).expect("Unable to write file.");
}

} ```

Creating a new vCard

```rust use vcard_parser::vcard::Vcard;

fn main () { let mut vcard = Vcard::default(); vcard.addproperty("NICKNAME:Johnny").unwrap(); println!("{}", vcard.tostring()); } ```

Parsing a single vCard without error checking

```rust use vcard_parser::vcard::Vcard;

fn main () { let mut vcard = Vcard::from("VERSION:4.0\nFN:John Doe\n"); vcard.addproperty("NICKNAME:Johnny").expect("Unable to add property."); println!("{}", vcard.tostring()); } ```

Parsing a single vCard with error checking

```rust use vcard_parser::vcard::Vcard;

fn main () { let mut vcard = Vcard::tryfrom("VERSION:4.0\nFN:John Doe\n").expect("Unable to parse input."); vcard.addproperty("NICKNAME:Johnny").expect("Unable to add property."); println!("{}", vcard.to_string()); } ```