Expand description
§JSContact
This crates implements types for the JSContact format as defined in RFC 9553.
To start using this crate, run the following command in your project directory:
cargo add jscontactSimple deserialization example:
use jscontact::Card;
use serde_json;
let json_value = serde_json::json!({
"@type": "Card",
"version": "1.0",
"uid": "1234"
});
let card_deserialized: Card = Card::try_from(json_value).unwrap(); // deserialize from serde::Value
let card_string: String = String::try_from(card_deserialized.clone()).unwrap(); // serialize to String
let card: Card = card_string.parse().unwrap(); // deserialize with parse()
assert_eq!(card_deserialized, card);Simple creation example:
use jscontact::{Card, CardKind, CardVersion, Name, NameComponent, NameComponentKind};
use serde_json;
let mut card = Card::new(CardVersion::OneDotZero, "my:uri");
card.kind = Some(CardKind::Individual);
let json = serde_json::to_string(&card).unwrap(); // serialize with serdeGet localized Card:
use jscontact::{Card, CardVersion, Name};
use std::collections::HashMap;
use serde_json::Value;
// create a card
let mut card = Card::new(CardVersion::OneDotZero, "my:uri");
let mut name = Name::default();
name.full = Some("John".to_string());
card.name = Some(name);
// add localization
let mut translations: HashMap<String, Value> = HashMap::new();
let mut name_en = Name::default();
name_en.full = Some("Johny".to_string());
translations.insert(
"name".to_string(),
serde_json::to_value(name_en).expect("Failed to serialize name"),
);
card.add_localization("en", translations);
// use localized card
let langs = card.get_available_languages();
assert_eq!(langs, vec!["en"]);
let localized = card.get_localized(&langs[0]).unwrap();
assert_eq!(localized.name.unwrap().full.unwrap(), "Johny");Re-exports§
pub use card::Card;
Modules§
- card
- The primary Card object as defined in RFC 9553
Structs§
- Address
- The addresses of the entity represented by the Card, such as postal addresses or geographic locations.
- Address
Component - The components that make up the address.
- Anniversary
- Represents memorable dates and events for the entity.
- Author
- The author of a note.
- Calendar
crate::ResourceThe calendaring resources of the entity represented by the Card, such as to look up free-busy information.- Crypto
Key crate::ResourceThe cryptographic resources such as public keys and certificates associated with the entity represented by the Card.- Directory
crate::ResourceThe directories containing information about the entity represented by the Card.- Email
Address - Defines email addresses associated with the entity.
- Language
Pref - Represents preferred languages for communication.
- Link
crate::ResourceThe links to resources that do not fit any of the other use-case-specific resource properties.- Media
crate::ResourceThe media resources such as photographs, avatars, or sounds that are associated with the entity represented by the Card.- Name
- Defines the Name object, which contains information about the entity’s name components.
- Name
Component - Represents individual components of a name, such as given name or surname.
- Nickname
- Defines the Nickname object, which includes nicknames for the entity.
- Note
- The free-text notes that are associated with the Card.
- Online
Service - Represents online services such as social media or messaging accounts.
- OrgUnit
- Represents a unit within an organization, such as a department.
- Organization
- Represents an Organization object containing company or organization information.
- Partial
Date - A PartialDate object represents a complete or partial calendar date in the Gregorian calendar. It represents a complete date, a year, a month in a year, or a day in a month.
- Personal
Info - The personal information of the entity represented by the Card.
- Phone
- Defines phone numbers for the entity, including features like voice or text.
- Pronouns
- Defines pronouns used for the entity, such as they/them.
- Relation
- Represents the Relation object for associating related Cards.
- Resource
- The Resource data type defines a resource associated with the entity represented by the Card Resource is exposed for utility purposes. It is used to define common properties for all resources. It is not intended to be used directly.
- Scheduling
Address - The scheduling addresses by which the entity may receive calendar scheduling invitations.
- Speak
ToAs - Represents how to address or refer to the entity, including grammatical gender and pronouns.
- Timestamp
- Timestamp
- Title
- Represents titles or roles of the entity, such as job titles or functional positions.
Enums§
- Address
Component Kind - The kind of the address component.
- Address
Context - The contexts in which to use this address.
- Anniversary
Kind - The kind of anniversary
- Calendar
Kind - Calendar kind
- Card
Kind - The kind of the entity the Card represents.
- Card
Version - Represents the card version.
- Context
- The contexts in which to use the contact information. For example, someone might have distinct phone numbers for work and private contexts and may set the desired context on the respective phone number in the phones property.
- Date
Object - Represents a date object, which can be a timestamp or a partial date.
- Directory
Kind - Directory kind
- Grammatical
Gender - The grammatical gender to use in salutations and other grammatical constructs. For example, the German language distinguishes by grammatical gender in salutations such as “Sehr geehrte” (feminine) and “Sehr geehrter” (masculine).
- Link
Kind - Link kind
- Media
Kind - Media kind
- Name
Component Kind - The kind of the name component.
- Personal
Info Kind - The kind of personal information.
- Personal
Info Level - The level of expertise or engagement in hobby or interest.
- Phone
Feature - The set of contact features that the phone number may be used for.
- Phonetic
System - The phonetic system used in the related value of the phonetic property.
- Relationship
Type - the IANA-registered TYPE [IANA-vCard] parameter values of the vCard RELATED property (Section 6.6.6 of RFC6350):
- Title
Kind - Title kind