[][src]Crate om2

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 methods
  • getset_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.

Structs

Measure

A numeric value with its unit of measure.

Enums

NumericUnion

A datatype that is the union of numeric xsd data types. "numericUnion" is equivalent to the xsd specification that uses an xsd:union of memberTypes="xsd:decimal xsd:double xsd:float xsd:integer".

Unit

A unit of measure is a definite magnitude of a quantity, defined and adopted by convention or by law. It is used as a standard for measurement of the same quantity, where any other value of the quantity can be expressed as a simple multiple of the unit. For example, length is a quantity; the metre is a unit of length that represents a definite predetermined length. When we say 10 metre (or 10 m), we actually mean 10 times the definite predetermined length called "metre".