4 releases
new 0.2.2 | Jan 7, 2025 |
---|---|
0.2.1 | Jan 7, 2025 |
0.2.0 | Jan 7, 2025 |
0.1.0 | Jan 7, 2025 |
#98 in Biology
310 downloads per month
135KB
2K
SLoC
Rust bindings for Phenopacket Schema
See the documentation on docs.rs for usage examples and more info.
lib.rs
:
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 programatically
Any struct or enums of the schema can be created by invoking its initializer.
For instance, an schema::v2::core::OntologyClass
:
use phenopackets_dev::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");
Encode/decode into protobuf binary format
The schema elements can be encoded or decoded into bytes:
use phenopackets_dev::schema::v2::core::OntologyClass;
use prost::Message;
let seizure = OntologyClass {
id: "HP:0001250".into(),
label: "Seizure".into(),
};
// Dump to bytes ...
let bytes: Vec<u8> = seizure.encode_to_vec();
// ... and read back.
let other = OntologyClass::decode(&bytes[..]).unwrap();
assert_eq!(seizure, other);
Note, only the protobuf binary format is implemented (no JSON, YAML, ...).
Dependencies
~0.4–2.2MB
~31K SLoC