Crate jscontact

Crate jscontact 

Source
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 jscontact

Simple 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 serde

Get 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.
AddressComponent
The components that make up the address.
Anniversary
Represents memorable dates and events for the entity.
Author
The author of a note.
Calendar
crate::Resource The calendaring resources of the entity represented by the Card, such as to look up free-busy information.
CryptoKey
crate::Resource The cryptographic resources such as public keys and certificates associated with the entity represented by the Card.
Directory
crate::Resource The directories containing information about the entity represented by the Card.
EmailAddress
Defines email addresses associated with the entity.
LanguagePref
Represents preferred languages for communication.
Link
crate::Resource The links to resources that do not fit any of the other use-case-specific resource properties.
Media
crate::Resource The 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.
NameComponent
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.
OnlineService
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.
PartialDate
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.
PersonalInfo
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.
SchedulingAddress
The scheduling addresses by which the entity may receive calendar scheduling invitations.
SpeakToAs
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§

AddressComponentKind
The kind of the address component.
AddressContext
The contexts in which to use this address.
AnniversaryKind
The kind of anniversary
CalendarKind
Calendar kind
CardKind
The kind of the entity the Card represents.
CardVersion
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.
DateObject
Represents a date object, which can be a timestamp or a partial date.
DirectoryKind
Directory kind
GrammaticalGender
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).
LinkKind
Link kind
MediaKind
Media kind
NameComponentKind
The kind of the name component.
PersonalInfoKind
The kind of personal information.
PersonalInfoLevel
The level of expertise or engagement in hobby or interest.
PhoneFeature
The set of contact features that the phone number may be used for.
PhoneticSystem
The phonetic system used in the related value of the phonetic property.
RelationshipType
the IANA-registered TYPE [IANA-vCard] parameter values of the vCard RELATED property (Section 6.6.6 of RFC6350):
TitleKind
Title kind