Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A Rust macro to generate a library to statically encapsulate numbers in objects having a unit of measurement

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

carlomilanesi/measures-rs

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 Rust applications that use numeric values having units of measurement. Such units 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.

In other libraries, this is achieved through compile-time dimensional analysis.

The documentation is in these files:

  • Motivation: It describes the advantages of using this library instead of using primitive numbers or libraries performing dimensional analysis.
  • 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. At the beginning of any source files, there are instructions about how to run them:

  • base, mks, si, user_defined_unit: Translation for use with the library Measures of the examples included in the crate uom version 0.35.0.
  • bench: Simple check of speed, comparing the performance using primitive numbers, exact measures, and approximate measures.
  • full: It prints all the provided examples of units of measurement, and the results of any supported operation.
  • matrix-mul: It computes the performance of matrix multiplication, using several libraries and algorithms. The library used are nalgebra, faer, ndarray, and measures.
  • nbody-naked, nbody-measures, nbody-approx-measures: Benchmark simulating the movements of four planets around the sun, taken from The Computer Language Benchmarks Game. The first program is the original benchmark, not using any external libraries, nor units of measurement. The second one is a translation of that code to a version using the library Measures, with exact values. The third one is a version using the library Measures, with approximate values and propagation of uncertainties.
  • air-mass-naked and air-mass-measures: Program taken from the Rosetta Code website. In particular, the first one is the original version, without units of measurement, taken from https://rosettacode.org/wiki/Air_mass#Rust. The second one is a version in which units of measurement are specified by using the library Measures.
  • haversine-naked, haversine-measures: Program taken from the Rosetta Code website. In particular, the first one is the original version, without units of measurement, taken from https://rosettacode.org/wiki/Haversine_formula#Rust. The second one is a version in which units of measurement are specified by using the library Measures.
  • resistor-mesh-naked.cpp, resistor-mesh-naked, resistor-mesh-measures: Programs taken from the Rosetta Code website. In particular, the first one is the C++ version, taken from https://rosettacode.org/wiki/Resistor_mesh#C++. The second one is the Rust version, without units of measurement, taken from https://rosettacode.org/wiki/Resistor_mesh#Rust, with some fixes. The third one is a version in which units of measurement are specified by using the library Measures.

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.

About

A Rust macro to generate a library to statically encapsulate numbers in objects having a unit of measurement

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •