qtty-core

Crates.ioqtty-core
lib.rsqtty-core
version0.2.2
created_at2025-12-12 20:19:35.595713+00
updated_at2026-01-13 21:09:18.451298+00
descriptionCore types for zero-cost strongly-typed physical quantities.
homepage
repositoryhttps://github.com/Siderust/qtty
max_upload_size
id1982068
size262,739
Vallés Puig, Ramon (VPRamon)

documentation

https://docs.rs/qtty-core

README

qtty-core

Crates.io Docs.rs

Zero-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 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

[dependencies]
qtty-core = "0.1.0"

Quick start

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);

Defining your own unit

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_std

Disable 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 }

Feature flags

  • 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.

License

AGPL-3.0 (see ../LICENSE).

Commit count: 1

cargo fmt