Crate gedcomx

Source
Expand description

§GEDCOM X

GEDCOM X defines an open data model and an open serialization format for exchanging the genealogical data essential to the genealogical research process. Examples of these data include information about persons, the relationships between persons, and the records that support that information.

This library provides the base types necessary to implement the GEDCOM X conceptual model and aims to implement further extensions to this model in the future. The goal of the library is to provide a correct, hard-to-misuse API that can handle serialization / deserialization to and from both JSON and XML. It’s intended to be a solid foundational building block that other genealogical software can be built on top of.

§Examples

§Deserialize a GEDCOM X document from JSON

use gedcomx::Gedcomx;

let json = std::fs::read_to_string("../data/birth.json").unwrap();
let gx = Gedcomx::from_json_str(&json).unwrap();
println!(
    "Successfully deserialized GEDCOM X document from JSON with {} people inside!",
    gx.persons.len()
);

assert_eq!(gx.persons.len(), 4);

§Build and serialize a GEDCOM X document to JSON

Most of the GEDCOM X types have lots of properties. Builders are provided for most types to conveniently set only the properties you choose to. Builders can be created with the builder method on the specific type. This method will take any required argument the final type needs to have set. Other properties can then be set on the builder. After the builder has been fully configured, it can be transformed into an instance of the type it is building by calling the build method on it.

use gedcomx::{Gedcomx, Name, NameForm, NameType, Person};

let gx = Gedcomx::builder()
    .person(
        Person::builder()
            .private(true)
            .name(
                Name::builder(
                    NameForm::builder()
                        .full_text("Jim Halpert")
                        .lang("en")
                        .build(),
                )
                .name_type(NameType::BirthName)
                .build(),
            )
            .build(),
    )
    .build();

let json = gx.to_json_string_pretty().unwrap();

assert_eq!(json.len(), 285);

§Deserialize a GEDCOM X document from XML

use gedcomx::Gedcomx;

let xml = std::fs::read_to_string("../data/birth.xml").unwrap();
let gx = Gedcomx::from_xml_str(&xml).unwrap();
println!(
    "Successfully deserialized GEDCOM X document from XML with {} people inside!",
    gx.persons.len()
);

assert_eq!(gx.persons.len(), 4);

§Build and serialize a GEDCOM X document to XML

use gedcomx::{Gedcomx, Name, NameForm, NameType, Person};

let gx = Gedcomx::builder()
    .person(
        Person::builder()
            .private(true)
            .name(
                Name::builder(
                    NameForm::builder()
                        .full_text("Jim Halpert")
                        .lang("en")
                        .build(),
                )
                .name_type(NameType::BirthName)
                .build(),
            )
            .build(),
    )
    .build();

let xml = gx.to_xml_string_pretty().unwrap();

assert_eq!(xml.len(), 277);

Re-exports§

Modules§

Structs§

Enums§

Type Aliases§