| Crates.io | qtty-core |
| lib.rs | qtty-core |
| version | 0.2.2 |
| created_at | 2025-12-12 20:19:35.595713+00 |
| updated_at | 2026-01-13 21:09:18.451298+00 |
| description | Core types for zero-cost strongly-typed physical quantities. |
| homepage | |
| repository | https://github.com/Siderust/qtty |
| max_upload_size | |
| id | 1982068 |
| size | 262,739 |
qtty-coreZero-cost building blocks for strongly typed physical quantities.
This crate contains the minimal type system used by the qtty facade:
Quantity<U>] — an f64 tagged with a zero-sized unit marker typeUnit] and [Per<N, D>] — traits/types that encode conversion ratios and derived unitsMost 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.).
[dependencies]
qtty-core = "0.1.0"
Convert between built-in 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:
use qtty_core::length::{Meter, Meters};
use qtty_core::time::{Second, Seconds};
use qtty_core::velocity::Velocity;
let distance = Meters::new(100.0);
let time = Seconds::new(20.0);
let v: Velocity<Meter, Second> = distance / time;
assert!((v.value() - 5.0).abs() < 1e-12);
qtty-core pairs with the qtty-derive proc-macro to make new unit marker types trivial:
use qtty_core::{length::{Length, Meter}, Quantity};
use qtty_derive::Unit as UnitDerive;
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, UnitDerive)]
#[unit(symbol = "fur", dimension = Length, ratio = 201.168)]
pub struct Furlong;
let dist: Quantity<Furlong> = Quantity::new(3.0);
assert!((dist.to::<Meter>().value() - 603.504).abs() < 1e-12);
The derive fills in the Unit impl and a Display implementation automatically.
no_stdDisable default features to build qtty-core without std (it falls back to libm for floating-point math):
[dependencies]
qtty-core = { version = "0.1.0", default-features = false }
std (default): enables std support.serde: serializes/deserializes Quantity<U> as bare f64 values.pyo3: enables PyO3 conversions for Quantity<U> and Python interop traits.AGPL-3.0 (see ../LICENSE).