1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! Rust bindings for Phenopacket Schema.
//!
//! The crate contains Rust structs and enums generated from Phenopacket Schema protobuf descriptors.
//! Phenopacket Schema versions v1 and v2 are supported.
//!
//! # Examples
//!
//! ## Create a Phenopacket Schema element programmatically
//!
//! Any struct or enum of the schema can be created by invoking its initializer.
//! For instance, an [`schema::v2::core::OntologyClass`]:
//!
//! ```rust
//! use phenopackets::schema::v2::core::OntologyClass;
//!
//! let seizure = OntologyClass {
//! id: "HP:0001250".into(),
//! label: "Seizure".into(),
//! };
//!
//! assert_eq!(&seizure.id, "HP:0001250");
//! assert_eq!(&seizure.label, "Seizure");
//! ```
//!
//! ## JSON
//!
//! Phenopacket Schema elements can be read from or written into JSON format.
//! The functionality is gated by the `serde` feature
//! which derives Serde's `Serialize` and `Deserialize` traits
//! for all Phenopacket Schema components and enables interoperability
//! with Serde data formats, such as JSON.
//!
//! The following must be added into your `Cargo.toml` file
//! to read a phenopacket from a JSON file.
//! The `serde` feature must be enabled for `phenopackets`
//! and [serde_json](https://docs.rs/serde_json/latest/serde_json/)
//! must be added:
//!
//! ```toml
//! phenopackets = { version = "*", features = ["serde"]}
//! serde_json = "1.0.140"
//! ```
//!
//! Then, a phenopacket can be read
//! from a [JSON file](https://github.com/P2GX/phenopackets-rust/blob/master/data/v2/phenopacket.json):
//!
//! ```
//! use phenopackets::schema::v2::Phenopacket;
//!
//! // An example phenopacket
//! let path = "data/v2/phenopacket.json";
//! let bytes = std::fs::read(path).expect("Reading should succeed");
//!
//! # #[cfg(feature = "serde")]
//! let pp: Phenopacket = serde_json::from_reader(&bytes[..]).expect("Expecting no decoding issues");
//!
//! # #[cfg(feature = "serde")]
//! assert_eq!(pp.id, "comprehensive-phenopacket-id");
//! ```
//!
//! ## Protobuf wire format
//!
//! The schema elements can be encoded into or decoded from bytes:
//!
//! ```rust
//! use phenopackets::schema::v2::core::OntologyClass;
//! use prost::Message;
//!
//! let seizure = OntologyClass {
//! id: "HP:0001250".into(),
//! label: "Seizure".into(),
//! };
//!
//! // Encode the component into bytes ...
//! let bytes: Vec<u8> = seizure.encode_to_vec();
//!
//! // ... and decode them back.
//! let decoded = OntologyClass::decode(&bytes[..]).unwrap();
//!
//! assert_eq!(seizure, decoded);
//! ```
//!
//! # Feature flags
//!
//! Phenopackets uses [feature flags](https://doc.rust-lang.org/cargo/reference/features.html) to enable
//! adding optional functionality.
//!
//! No features are turned on by default.
//!
//! ## Optional feature flags
//!
//! The following features customize Phenopackets' behavior:
//!
//! - `serde`: Enables interoperability with [serde](https://docs.rs/serde/latest/serde) to support encoding into or decoding from JSON format.
//!
/// The source files generated by prost crate.
pub
pub
// Include the `phenopackets` module, which is generated from the Phenopacket Schema proto files.
// Public-facing modules.