unitscale_macros

Crates.iounitscale_macros
lib.rsunitscale_macros
version0.1.7
created_at2025-04-11 02:11:34.245772+00
updated_at2025-04-15 20:25:15.503574+00
descriptionUnitScale macros for simplifying conversions over bus communication
homepage
repositoryhttps://gitlab.com/goosegrid/unitscale
max_upload_size
id1629127
size25,670
David Kalliecharan (ddkn)

documentation

https://docs.rs/unitscale_macros

README

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)]
struct Scale0_1;

#[unit_data]
struct Volts;

let v = Volts::<Scale0_1, u16>::try_from(3.2).unwrap();
// v.to_f64() gives back 3.2 within the precision limit of the type (e.g. u16)
assert_eq!(v.scaled_value(), 32);
Commit count: 24

cargo fmt