Skip to main content

Crate jcard

Crate jcard 

Source
Expand description

RFC 7095 jCard — JSON representation of vCard.

Provides typed Rust structures for jCard documents with serde serialization/deserialization matching the RFC 7095 JSON array format.

§Lenient Parsing

JCard::from_json returns Parsed<JCard> — the best-effort parse result plus any ParseWarning entries for malformed properties. This follows the EIDO pattern for NG9-1-1: calltakers see all available data while discrepancy reports capture what went wrong.

The serde Deserialize impl is also available for simple use cases where warnings are not needed. By default it returns Err on structural failures; enable the lenient-deserialize feature to return an empty JCard instead (useful when embedding jCard in a parent struct that must not fail on malformed contact data).

§Value Types

All RFC 7095 §3.5 value types are supported as PropertyValue variants: text, uri, date, time, date-time, date-and-or-time, timestamp, boolean, integer, float, utc-offset, language-tag, and unknown. Structured property values (e.g. N, ADR) use PropertyValue::Structured with StructuredComponent elements, including nested arrays per §3.3.1.3.

The type identifier is stored on Property::value_type separately from the value, ensuring round-trip fidelity for all types including extensions.

§Examples

use jcard::JCard;

// Lenient parsing with warnings
let parsed = JCard::from_json(r#"["vcard",[["version",{},"text","4.0"]]]"#).unwrap();
assert!(!parsed.has_warnings());

// Simple serde path (warnings discarded)
let jcard: JCard = serde_json::from_str(r#"["vcard",[["version",{},"text","4.0"]]]"#).unwrap();

Re-exports§

pub use error::Error;
pub use property::EmptyParamValue;
pub use property::ParamValue;
pub use property::Property;
pub use property::PropertyValue;
pub use property::StructuredComponent;

Modules§

error
Error types for jCard parsing.
property
jCard property types per RFC 7095 §3.

Macros§

param_values
Creates a ParamValue with compile-time validation.

Structs§

JCard
A jCard document (RFC 7095).
JCardBuilder
Builder for constructing jCard documents with common properties.
ParseWarning
Warning emitted during lenient jCard parsing.
Parsed
Result of lenient jCard parsing: the parsed value plus any warnings.