9 releases
0.1.9 | Sep 21, 2020 |
---|---|
0.1.8 | Jun 4, 2020 |
0.1.7 | May 29, 2020 |
#1540 in Data structures
Used in vf-rs
135KB
639 lines
OM2
This crate is a loose attempt at creating a Unit
struct based off of the units
available in the OM2 ontology. It also exports Measure
and NumericUnion
classes.
All structs/enums exported are (de)serializable via Serde.
use om2::{Unit, Measure, NumericUnion};
let measure = Measure::builder()
.has_unit(Unit::Hour)
.has_numerical_value(NumericUnion::Integer(7))
.build().unwrap();
assert_eq!(measure.has_unit(), &Unit::Hour);
assert_eq!(measure.has_numerical_value(), &NumericUnion::Integer(7));
lib.rs
:
This is an auto-generated wrapper around the om2:Unit
class, with a few
supporting structs/enums/utils.
The idea here is to map Unit into a big (de)serializable rust enum, so you don't need to know the label/symbol up front but can just grab it from the Unit enum:
use om2::Unit;
let wh = Unit::WattHour;
assert_eq!(wh.symbol(), Some("W h".to_string()));
assert_eq!(wh.label(), Some("watt hour".to_string()));
Note that the symbol()
and label()
methods return Option because not all
the enum values have those fields defined int he schema.
This crate also exports om2:Measure
, useful for holding full measurements.
It also has getters by default, with the option to include setters as well:
use om2::{Unit, Measure, NumericUnion};
let measure = Measure::new(7.3 as f64, Unit::Hour);
assert_eq!(measure.has_unit(), &Unit::Hour);
assert_eq!(measure.has_numerical_value(), &NumericUnion::Double(7.3));
Note that none of the available RDF/XML rust libs were able to parse the om2
RDF schema, so this library requires conversion to .ttl first (this is done
via the make schema
command, which uses the rapper
command line util
under the hood).
Features:
getset_setters
- implements setters on the generated structs so they can be mutated in-place via setter methodsgetset_getmut
- implements mutable getters on the generated structs so they can be mutated in-place via &mut getters
Note that all features are enabled when building the docs to give a sense of the library's full abilities.
Dependencies
~0.9–1.7MB
~35K SLoC