qtty-core
Zero-cost building blocks for strongly typed physical quantities.
This crate contains the minimal type system used by the qtty facade:
- [
Quantity<U>] — anf64tagged with a zero-sized unit marker type - [
Unit] and [Per<N, D>] — traits/types that encode conversion ratios and derived units - Predefined unit modules grouped by dimension (length, time, mass, angular, power, frequency, velocity)
Most users should depend on qtty. Reach for qtty-core when you need the primitives directly (custom units,
embedded/no_std builds, serialization without the facade, etc.).
Install
[]
= "0.1.0"
Quick start
Convert between built-in units:
use ;
let km = new;
let m = km.;
assert!;
Compose derived units:
use ;
use ;
use Velocity;
let distance = new;
let time = new;
let v: = distance / time;
assert!;
Defining your own unit
qtty-core pairs with the qtty-derive proc-macro to make new unit marker types trivial:
use ;
use Unit as UnitDerive;
;
let dist: = new;
assert!;
The derive fills in the Unit impl and a Display implementation automatically.
no_std
Disable default features to build qtty-core without std (it falls back to libm for floating-point math):
[]
= { = "0.1.0", = false }
Feature flags
std(default): enablesstdsupport.serde: serializes/deserializesQuantity<U>as baref64values.pyo3: enables PyO3 conversions forQuantity<U>and Python interop traits.
License
AGPL-3.0 (see ../LICENSE).