Expand description
Core type system for strongly typed physical quantities.
qtty-core provides a minimal, zero-cost units model:
- A unit is a zero-sized marker type implementing
Unit. - A value tagged with a unit is a
Quantity<U>, backed by anf64. - Conversion is an explicit, type-checked scaling via
Quantity::to. - Derived units like velocity are expressed as
Per<N, D>(e.g.Meter/Second).
Most users should depend on qtty (the facade crate) unless they need direct access to these primitives.
§What this crate solves
- Compile-time separation of dimensions (length vs time vs angle, …).
- Zero runtime overhead for unit tags (phantom types only).
- A small vocabulary to express derived units via type aliases (
Per,DivDim).
§What this crate does not try to solve
- Exact arithmetic (
Quantityisf64). - General-purpose symbolic simplification of arbitrary unit expressions.
- Automatic tracking of exponent dimensions (
m^2,s^-1, …); only the expression forms represented by the provided types are modeled.
§Quick start
Convert between predefined units:
use qtty_core::length::{Kilometers, Meter};
let km = Kilometers::new(1.25);
let m = km.to::<Meter>();
assert!((m.value() - 1250.0).abs() < 1e-12);Compose derived units using /:
use qtty_core::length::{Meter, Meters};
use qtty_core::time::{Second, Seconds};
use qtty_core::velocity::Velocity;
let d = Meters::new(100.0);
let t = Seconds::new(20.0);
let v: Velocity<Meter, Second> = d / t;
assert!((v.value() - 5.0).abs() < 1e-12);§no_std
Disable default features to build qtty-core without std:
[dependencies]
qtty-core = { version = "0.1.0", default-features = false }When std is disabled, floating-point math that isn’t available in core is provided via libm.
§Feature flags
std(default): enablesstdsupport.serde: enablesserdesupport forQuantity<U>; serialization is the rawf64value only.
§Panics and errors
This crate does not define an error type and does not return Result from its core operations. Conversions and
arithmetic are pure f64 computations; they do not panic on their own, but they follow IEEE-754 behavior (NaN and
infinities propagate according to the underlying operation).
§SemVer and stability
This crate is currently 0.x. Expect breaking changes between minor versions until 1.0.
Re-exports§
pub use units::angular;pub use units::frequency;pub use units::length;pub use units::mass;pub use units::power;pub use units::time;pub use units::unitless;pub use units::velocity;
Modules§
- units
- Predefined unit modules (grouped by dimension).
Macros§
- impl_
unit_ conversions - Generates
Fromtrait implementations for all pairs of units within a dimension.
Structs§
- DivDim
- Dimension formed by dividing one
Dimensionby another. - Per
- Unit representing the division of two other units.
- Quantity
- A quantity with a specific unit.
- Unitless
- Zero-sized marker type for dimensionless quantities.
Enums§
- Dimensionless
- Dimension for dimensionless quantities.