dimensional_analyser
A small Rust library for runtime dimensional analysis and unit conversion.
This crate provides:
- A
Dimensiontype representing derived physical dimensions (exponents and scaling factor). - A
Quantitytype that combines a numeric value with aDimensionand supports arithmetic and conversion. - Algorithms to compute exponents required to express a target dimension as a product of base dimensions (uses a Bareiss elimination solver internally).
- Several predefined unit systems (SI and example unit sets) in
src/dimensions/.
The library is designed to be flexible: you can create new base dimensions at runtime, apply metric prefixes, raise dimensions to powers, and convert between compatible quantities (including exponent-aware conversions, e.g. area/length conversions).
Features
- Create base dimensions dynamically with
Dimension::new. - Compose and manipulate derived dimensions with multiplication, division and powering.
- Convert between quantities that are compatible via exponent solving (e.g., derive energy from mass, length and time).
- Includes unit collections in
src/dimensions/such as an SI-like set. Tests demonstrate conversions with imperial and other example units.
Quick example
Example usage (based on src/main.rs and the library docs):
use ;
Crate layout / API overview
src/dimension.rs— coreDimensiontype, prefixes, exponent algebra, conversion-exponent calculation.src/quantity.rs—Quantitytype, arithmetic (+, -, *, /), and conversion helpers for multiple quantities.src/bareiss_eliminator.rs— helper matrix code and Bareiss elimination solver used to compute exponents.src/dimensions/— predefined unit sets (e.g., SI-like units, examples).
Publicly exported items include (non exhaustive):
Dimensionand helpers likePrefixand convenience methods (square,cube,power,prefix).Quantitywithnew,convert_to, arithmetic and inspection helpers.dim!macro and constant-backed unit sets indimensions.
Refer to the crate-level docs in src/lib.rs for a short annotated example.
There are optional features defined in Cargo.toml: debug-print and sci-notation
Contributing
- Bug reports and pull requests are welcome. Please include small, focused changes and tests when appropriate.
- Prefer small, well-documented commits.
Notes
- This project includes an internal Bareiss matrix solver implementation used for solving the exponent linear systems; tests cover many of those cases.