Crate unitscale_macros

Source
Expand description

§unitscale_macros

§Overview

unitscale_macros provides procedural macros to simplify creating unit types and scale constants. This crate depends on unitscale_core and is intended to reduce boilerplate.

It exports two attribute macros:

  • #[unit_scale(to = float)]: Declares a scale struct implementing UnitScale.
  • #[unit_data]: Generates a generic struct for the unit and implements TryFrom<f64>, Scaled<U>, and new().

§Example

use unitscale_core::*;
use unitscale_macros::*;

#[unit_scale(to = 0.1)]
pub struct Scale0_1;

#[unit_data]
pub struct Volts;

let v = Volts::<Scale0_1, u16>::try_from(3.2).unwrap();
assert_eq!(v.value(), 32);

§Licensing

For licensing information, please refer to the LICENSE file in each crate.

Attribute Macros§

unit_data
unit_data macro to create a valid scaled value bounds of U
unit_scale
unit_scale macro to create a valid scaler