| Crates.io | mathengine-units |
| lib.rs | mathengine-units |
| version | 0.1.0 |
| created_at | 2025-10-06 23:48:34.327325+00 |
| updated_at | 2025-10-06 23:48:34.327325+00 |
| description | Comprehensive unit conversion system supporting multiple measurement dimensions |
| homepage | https://github.com/javif89/mathengine |
| repository | https://github.com/javif89/mathengine |
| max_upload_size | |
| id | 1871002 |
| size | 16,693 |
A comprehensive unit conversion system supporting multiple measurement dimensions.
m, meter, meters - Meterscm, centimeter, centimeters - Centimetersmm, millimeter, millimeters - Millimeterskm, kilometer, kilometers - Kilometersft, foot, feet - Feetin, inch, inches - Inchesyd, yard, yards - Yardsmi, mile, miles - MilesC, celsius - CelsiusF, fahrenheit - FahrenheitK, kelvin - Kelvinuse mathengine_units::{
length::LengthDimension,
temperature::TemperatureDimension,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Length conversions
let meters = LengthDimension::from_unit("m", 10.0)?;
let feet_unit = LengthDimension::parse_unit("feet")?;
let feet = meters.convert_to(feet_unit);
println!("10 meters = {} feet", feet.value()); // ~32.8 feet
// Temperature conversions
let celsius = TemperatureDimension::from_unit("C", 23.0)?;
let fahrenheit_unit = TemperatureDimension::parse_unit("F")?;
let fahrenheit = celsius.convert_to(fahrenheit_unit);
println!("23°C = {}°F", fahrenheit.value()); // 73.4°F
Ok(())
}
The system prevents invalid conversions at compile time:
use mathengine_units::{length::LengthDimension, temperature::TemperatureDimension};
// This won't compile - can't convert length to temperature
// let invalid = length_meters.convert_to(temperature_unit); // ❌
Comprehensive error handling for runtime issues:
use mathengine_units::{length::LengthDimension, UnitError};
match LengthDimension::parse_unit("invalid_unit") {
Ok(unit) => println!("Valid unit: {:?}", unit),
Err(UnitError::UnknownUnit(unit)) => {
println!("Unknown unit: '{}'", unit);
}
}
Part of the mathengine workspace. This crate provides the foundation for unit-aware mathematical calculations and can be used independently in any application requiring unit conversions.
The architecture makes it easy to add new unit dimensions:
Licensed under either of Apache License, Version 2.0 or MIT license at your option.