Parses and validates vCard data according to RFC 6350 specification.
Add the library to the dependencies section of your cargo.toml file.
toml
[dependencies]
vcard_parser = "0.1.0"
Rust documentation here.
Reading a vcf file, updating the vCard object, and writing back to the file.
```rust use std::fs; use std::fs::readtostring; use vcardparser::parsetovcards; use vcardparser::vcard::property::types::PropertyType;
fn main () { if let Ok(string) = readtostring("contacts.vcf") { let mut vcards = parsetovcards(string.as_str()).unwrap();
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.");
}
} ```
```rust use vcard_parser::vcard::Vcard;
fn main () { let mut vcard = Vcard::tryfrom("VERSION:4.0\nFN:John Doe\n").unwrap(); vcard.addproperty("NICKNAME:Johnny").unwrap(); println!("{}", vcard.to_string()); } ```
```rust use vcard_parser::vcard::Vcard;
fn main () { let mut vcard = Vcard::default(); vcard.addproperty("NICKNAME:Johnny").unwrap(); println!("{}", vcard.tostring()); } ```