#vcard #parser #rfc6350

vcard_parser

Parses and validates vCard data according to RFC 6350 specification

5 releases

Uses new Rust 2021

new 0.2.1 Jan 23, 2023
0.2.0 Jan 23, 2023
0.1.2 Oct 30, 2022
0.1.1 Oct 29, 2022
0.1.0 Oct 13, 2022

#47 in Email

Download history 23/week @ 2022-10-08 11/week @ 2022-10-15 8/week @ 2022-10-22 57/week @ 2022-10-29 9/week @ 2022-11-05 7/week @ 2022-11-12 10/week @ 2022-11-19 3/week @ 2022-11-26 7/week @ 2022-12-03 7/week @ 2022-12-10 4/week @ 2022-12-17 12/week @ 2022-12-24 1/week @ 2022-12-31 6/week @ 2023-01-07 5/week @ 2023-01-14 51/week @ 2023-01-21

67 downloads per month
Used in vcard_tui

MIT license

355KB
8K SLoC

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.

[dependencies]
vcard_parser = "0.2.1"

Usage

Rust documentation is here.

Basic Example

Read a vcf file, update the vCard object, and write back to file.

use std::fs::{read_to_string, write};
use vcard_parser::parse_vcards;
use vcard_parser::traits::HasValue;
use vcard_parser::vcard::value::Value;
use vcard_parser::vcard::value::value_text::ValueTextData;

fn main () {
    let input = read_to_string("contacts.vcf").unwrap_or(String::from("BEGIN:VCARD\nVERSION:4.0\nFN:\nEND:VCARD\n"));
    let mut vcards = parse_vcards(input.as_str()).expect("Unable to parse string.");

    let vcard = vcards.first_mut().unwrap();
    let mut property = vcard.get_property_by_name("FN").unwrap();

    property.set_value(Value::from(ValueTextData::from("John Doe"))).unwrap();
    vcard.set_property(&property).expect("Unable to update property.");

    let mut data = String::new();
    for vcard in vcards {
        data.push_str(vcard.export().as_str())
    }

    write("contacts.vcf", data).expect("Unable to write file.");
}

Dependencies

~3.5MB
~98K SLoC