3 releases

0.1.10 Nov 22, 2023
0.1.9 Nov 16, 2023
0.1.3 Mar 2, 2023
0.1.2 Feb 24, 2023

#209 in Math

Download history 1/week @ 2024-03-09 59/week @ 2024-03-30 13/week @ 2024-04-06

63 downloads per month

GPL-3.0 license

2.5K SLoC


Rust library to build, calculate and convert custom engineering units.

License Tests codecov

Project Goals

  • Easy to use engineering units and calculations
  • No panics
  • No dependencies
  • 100% testing coverage

Example Usage

Creating units

let quarter_pounder = mass!(0.25, MassUnit::Pound);
assert_eq!(0.25, quarter_pounder.value);
assert_eq!("0.25 lb", quarter_pounder.to_string());

Converting units

let quarter_pounder = mass!(0.25, MassUnit::Pound);
let royal_with_cheese = quarter_pounder.convert(MassUnit::Kilogram);
assert_eq!("0.11 kg", royal_with_cheese.to_string());

Engineering calculations

let temp_1 = temperature!(4.0, TemperatureDeltaUnit::C);
let mass_1 = mass!(5.0, MassUnit::Kilogram);
let t_1 = time!(10.0, TimeUnit::Second);

let unit = temp_1 * mass_1 / t_1;
assert_eq!(2.0, unit.value);
assert_eq!("2.00 kg·°C/s", unit.to_string());

let double = 2.0 * unit;
assert_eq!(4.0, double.value);
assert_eq!("4.00 kg·°C/s", double.to_string());

let flip = double.reciprocal();
assert_eq!(0.25, flip.value);
assert_eq!("0.25 s/kg·°C", flip.to_string());

let mass_2 = mass!(10.0, MassUnit::Kilogram);
let canceled_out = flip * mass_2;
assert_eq!(2.50, canceled_out.value);
assert_eq!("2.50 s/°C", canceled_out.to_string());

Test coverage status



This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

No runtime deps