## eng-units

Engineering unit coversions and calculations

### 3 releases

 0.1.10 Nov 22, 2023 Nov 16, 2023 Mar 2, 2023 Feb 24, 2023

#209 in Math

99KB
2.5K SLoC

# eng-units

## 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());
``````