measures-rs 0.1.0

A Rust macro to generate a library to statically encapsulate numbers in objects having a unit of measurement, allowing any meaningful operation, but statically forbidding meaningless operations with them.
Documentation

measures-rs

Crates.io Docs.rs CI Coverage Status

Description

This repository contains the source code and the documentation of the library contained in the Rust-language crate: measures.

Its purpose is to improve the readability and correctness of applications using numeric values having units of measurement. These can be the ones used in physics or in geometry, but also the ones commonly used in industry.

This purpose is achieved by encapsulating such numbers into objects whose type represents their unit of measurement, and providing for such types only the operations which make sense.

The documentation is in these files:

  • Motivation: It describes the advantages of using this library instead of other libraries or naked numbers.
  • Tutorial: It is a step-by-step course on the use of this library.
  • Architecture: It explains the design choices of the library.

There are several examples:

  • full: Print of all the provided examples of units of measurement, and of the results of any supported operation.
  • bench, bench2: Simple check of speed, compared with naked numbers or with the crate nalgebra.
  • base, mks, si, unit: Translation for Measures of the examples included in the crate uom version 0.35.0.
  • nbody-measures: It is put beside example nbody-naked. The latter is a benchmark program not using any external libraries, nor units of measurement, taken from The Computer Language Benchmarks Game. The former is a translation to a version using this library. At the beginning of both files, it is explained how to use them. In a specific setting, it appears that nbody-measures takes 11% more time than nbody-naked.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See CONTRIBUTING.md.