| Crates.io | dimensional_analyser |
| lib.rs | dimensional_analyser |
| version | 0.2.0 |
| created_at | 2025-12-06 20:27:19.091165+00 |
| updated_at | 2025-12-28 06:13:57.815455+00 |
| description | Runtime dimensional analysis and unit-aware quantities for Rust |
| homepage | |
| repository | https://github.com/Taro9000/dimensional_analyser |
| max_upload_size | |
| id | 1970718 |
| size | 85,903 |
A small Rust library for runtime dimensional analysis and unit conversion.
This crate provides:
Dimension type representing derived physical dimensions (exponents and scaling factor).Quantity type that combines a numeric value with a Dimension and supports arithmetic and conversion.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).
Dimension::new.src/dimensions/ such as an SI-like set. Tests demonstrate conversions with imperial and other example units.Example usage (based on src/main.rs and the library docs):
use dimensional_analyser::{Result, dim, dimension::{DIMENSIONLESS, Dimension, Prefix}, dimensions::le_systeme_international_d_unites::{HOUR, JOULE, LITER, MINUTE, base_units::{KILOGRAM, METER, SECOND}}, quantity::{DimensionalAnalysableQuantity, Quantity}};
fn main() -> Result {
let height = Quantity::new(5 , dim!(METER));
let mass = Quantity::new(15, dim!(KILOGRAM));
let acceleration = Quantity::new(9.81,dim!(METER SECOND^-2));
let speed = Quantity::new(20, dim!(METER SECOND^-1));
let energy = dim!(JOULE);
let potential_energy = [&height, &mass, &acceleration].convert_to(energy)?;
let kinetic_energy = [&mass, &speed].convert_to(energy)? / 2;
let total_energy = (&potential_energy + &kinetic_energy)?;
println!("Potential energy: {}", potential_energy);
println!("Kinetic energy: {}", kinetic_energy);
println!("Total energy: {}", total_energy);
Ok(())
}
src/dimension.rs — core Dimension type, prefixes, exponent algebra, conversion-exponent calculation.src/quantity.rs — Quantity type, 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):
Dimension and helpers like Prefix and convenience methods (square, cube, power, prefix).Quantity with new, convert_to, arithmetic and inspection helpers.dim! macro and constant-backed unit sets in dimensions.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