Skip to main content

Crate qtty_derive

Crate qtty_derive 

Source
Expand description

Derive macro implementation used by qtty-core.

qtty-derive is an implementation detail of this workspace. By default the Unit derive expands in terms of crate::Unit and crate::Quantity, which matches qtty-core. Downstream crates can target the public qtty facade by adding crate = qtty to the helper attribute.

Most users should depend on qtty instead and use the predefined units.

§Generated impls

For a unit marker type MyUnit, the derive implements:

  • crate::Unit for MyUnit
  • when targeting the defining crate itself, formatting impls for crate::Quantity<MyUnit, S> (Display, LowerExp, UpperExp)

§Attributes

The derive reads a required #[unit(...)] attribute:

  • symbol = "m": displayed unit symbol
  • dimension = SomeDim: dimension marker type
  • ratio = 1000.0: conversion ratio to the canonical unit of the dimension
  • crate = qtty: optional crate path when deriving from a downstream crate

Derive Macros§

Unit
Derive crate::Unit and a Display impl for crate::Quantity<ThisUnit>.