qtty-derive

Crates.ioqtty-derive
lib.rsqtty-derive
version0.2.2
created_at2025-12-12 20:18:45.700981+00
updated_at2026-01-13 21:00:03.770474+00
descriptionProcedural macro derives for qtty-core.
homepage
repositoryhttps://github.com/Siderust/qtty
max_upload_size
id1982066
size14,992
Vallés Puig, Ramon (VPRamon)

documentation

https://docs.rs/qtty-derive

README

qtty-derive

Crates.io Docs.rs

Derive macro used by qtty-core to implement new unit marker types.

Most applications should depend on the qtty facade. Reach for qtty-derive only if you are extending the unit catalogue yourself or building a crate that mirrors the qtty crate root (Quantity, Unit, …).

Install

[dependencies]
qtty-core = "0.1.0"
qtty-derive = "0.1.0"

Usage

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(1.0);
assert!((dist.to::<Meter>().value() - 201.168).abs() < 1e-12);

The derive generates both the Unit impl (ratio, dimension tag, and symbol) and a Display implementation for Quantity<Furlong> that prints <value> <symbol>.

Attribute reference

The macro reads a required #[unit(...)] attribute with the following keys:

  • symbol = "m": string literal printed by the generated Display impl.
  • dimension = Length: dimension marker type implementing Dimension.
  • ratio = 1.0: conversion ratio to the canonical unit of the dimension (usually 1.0 for the base unit).

Additional metadata can be added in the future without breaking callers (unknown keys result in a compile error).

License

AGPL-3.0 (see ../LICENSE).

Commit count: 1

cargo fmt