space-units
Type-safe units of measure for aerospace quantities.
The Problem
In 1999, NASA lost the Mars Climate Orbiter because one team produced pound-force-seconds and another expected newton-seconds. Cost: $327.6 million.
Most codebases still represent physical quantities as plain f64:
The Solution
use *;
let distance = 384_400.km; // reads like "384,400 kilometers"
let time = 3.5.hours; // reads like "3.5 hours"
let velocity = distance / time; // Length / Time Velocity
// Read back in any unit
velocity.in_mps // 30_514.3...
velocity.in_kmps // 30.514...
// Only meaningful arithmetic compiles
let force = 1000.kg * 9.81.mps2; // Mass * Acceleration Force
let accel = force / 500.kg; // Force / Mass Acceleration
// let oops = force + 500.kg(); // COMPILE ERROR: can't add Force + Mass
Features
- 40 quantity types covering mechanics, electromagnetics, thermodynamics, propulsion, radiation, and orbital mechanics
- 80+ typed arithmetic operations so only physically valid math compiles
- Zero dependencies and sub-1s compile time
no_stdcompatible for flight software- Const constructors for compile-time initialization
Why not uom?
| space-units | uom | |
|---|---|---|
| Error messages | "expected Length, found Mass" |
"PInt vs Z0" (typenum internals) |
| Syntax | 384_400.km() |
Length::new::<kilometer>(384400.0) |
| Compile time | < 1s | ~6s |
| Const constructors | Yes | No (5+ years open) |
| nalgebra | Clean wrappers (planned) | Broken (4+ years open) |
| Dependencies | 0 | typenum, num-traits |
Quick Start
use *;
use *;
// Orbital velocity at ISS altitude
let r = 6_771.km; // Earth radius + 400 km
let v = .sqrt; // sqrt(mu/r) Velocity
println!; // "7.67 km/s"
// Propulsion
let isp = from_s; // Merlin 1D
let ve = isp.effective_exhaust_velocity; // Isp * g0 Velocity
let mdot = 100.kgps; // mass flow rate
let thrust = mdot * ve; // MassFlowRate * Velocity Force
// Electromagnetic
let v = 28.volts;
let i = 5.amperes;
let p = v * i; // Voltage * Current Power
// All arithmetic works both ways
let scaled = 2.0 * distance; // f64 * Quantity works
let ratio = distance / 100.km; // Quantity / Quantity f64
let mut d = distance;
d += 50.km; // compound assignment works
Supported Quantities
Mechanics
Length, Time, Mass, Velocity, Acceleration, Force, Impulse, Momentum
Angular Motion
Angle (with trig: sin/cos/tan/normalize), AngularVelocity, AngularAcceleration, Torque, AngularMomentum, MomentOfInertia, SolidAngle
Geometry
Energy & Thermodynamics
Energy, Power, Pressure, SpecificEnergy, Temperature (K/C/F/R), HeatFlux
Electromagnetic
Frequency (with period/wavelength), ElectricCurrent, Voltage, Resistance, ElectricCharge, MagneticFluxDensity, MagneticFlux, Capacitance, Inductance
Propulsion
Orbital Mechanics
GravitationalParameter, SpecificAngularMomentum
Radiation
AbsorbedDose (Gy/rad), DoseEquivalent (Sv/rem)
Communications
All types are accessible via use space_units::prelude::*. The NumericExt trait provides literal extensions on numeric types.
Typed Constants
use *;
C // Speed of light: Velocity
AU // Astronomical unit: Length
G0 // Standard gravity: Acceleration
GM_EARTH // Earth gravitational parameter: GravitationalParameter
GM_SUN // Sun gravitational parameter
R_EARTH // Earth mean radius: Length
M_EARTH // Earth mass: Mass
// ... 34 total (all planets, Moon, fundamental constants)
Formatting
use *;
let d = 384_400.km;
// Default Display shows canonical unit
println!; // "384400000 m"
println!; // "384400000.00 m"
// display_as() for specific units
println!; // "384400 km"
println!; // "0.0 AU"
Installation
Or add to your Cargo.toml:
[]
= "0.1"
Examples
Runnable examples in the examples/ directory:
Documentation
- API Reference — full docs on docs.rs
- Design — architecture and design decisions
- Roadmap — planned features and milestones
- Developer Experience — DX philosophy
- Contributing — how to contribute
Security
Please report vulnerabilities privately. See SECURITY.md for details.
License
Licensed under the Apache License, Version 2.0. See LICENSE.