jcard
RFC 7095 jCard (JSON representation of vCard) types with serde support.
All value types from RFC 7095 §3.5 are supported: text, uri, date, time, date-time, date-and-or-time, timestamp, boolean, integer, float, utc-offset, language-tag, and unknown. Structured property values with nested arrays (§3.3.1.3) are handled. Type identifiers are stored separately for round-trip fidelity, including extension types.
Usage
[]
= "0.3"
Builder
use JCard;
let jcard = builder
.fn_
.n
.email
.build;
let json = to_string_pretty.unwrap;
let parsed: JCard = from_str.unwrap;
assert_eq!;
Lenient parsing with warnings
use JCard;
let parsed = from_json.unwrap;
// Best-effort result is always available
assert_eq!;
// Warnings report what went wrong
for w in &parsed.warnings
Deserialization behavior
The serde Deserialize impl returns Err on structurally invalid jCard
input (wrong tag, not an array, etc.) by default. This is the expected
behavior for standalone use — the caller sees the error and decides what
to do.
When jCard is embedded as a field in a parent struct (e.g., EIDO's
agencyJcard: Option<JCard>), a deserialization error on the jCard
poisons the entire parent. Enable the lenient-deserialize feature to
return an empty JCard (with only the mandatory version property)
instead of Err:
[]
= { = "0.3", = ["lenient-deserialize"] }
Both paths discard warnings. Use from_json() or from_value() when
you need structured warning collection alongside the best-effort result.
From an existing serde_json::Value
use JCard;
let value: Value = from_str.unwrap;
let parsed = from_value.unwrap;
assert!;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.