| Crates.io | qtty-derive |
| lib.rs | qtty-derive |
| version | 0.2.2 |
| created_at | 2025-12-12 20:18:45.700981+00 |
| updated_at | 2026-01-13 21:00:03.770474+00 |
| description | Procedural macro derives for qtty-core. |
| homepage | |
| repository | https://github.com/Siderust/qtty |
| max_upload_size | |
| id | 1982066 |
| size | 14,992 |
qtty-deriveDerive 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, …).
[dependencies]
qtty-core = "0.1.0"
qtty-derive = "0.1.0"
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>.
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).
AGPL-3.0 (see ../LICENSE).