#si-units #units #physics #measurement #unit #no-alloc

macro no-std simple-si-units-macros

This is the procedural macro library for crate simple-si-units

24 releases (2 stable)

1.0.1 Apr 28, 2023
0.9.0 Apr 25, 2023
0.7.4 Mar 23, 2023
0.3.1 Nov 7, 2022

#25 in #si-units

Download history 38/week @ 2024-07-21 26/week @ 2024-07-28 18/week @ 2024-08-11 16/week @ 2024-08-18 22/week @ 2024-08-25 11/week @ 2024-09-01 14/week @ 2024-09-08 15/week @ 2024-09-15 24/week @ 2024-09-22 95/week @ 2024-09-29 18/week @ 2024-10-06 54/week @ 2024-10-13 69/week @ 2024-10-20 28/week @ 2024-10-27 13/week @ 2024-11-03

168 downloads per month
Used in 5 crates (via simple-si-units)

MPL-2.0 license

29KB
460 lines

simple-si-units-core

This crate exists to support the simple-si-units. Please go there for more information.

Contents

Crate simple-si-units-macros exports the following derive macros:

Unit

This macro uses the NumLike trait from simple-si-units-core to derive all of the relevant mathematical operators for the derived struct, so long as that struct contains only a single named field. For example:

use simple_si_units_macros::UnitStruct;
use simple_si_units_core::NumLike;

#[derive(UnitStruct, Debug, Clone)]
struct HyperVelocity<T: NumLike>{
  square_meters_per_second: T
}

fn weighted_hypervel_sum<T: NumLike>(a: HyperVelocity<T>, b: HyperVelocity<T>, weight: f64) -> HyperVelocity<T>
  where T:NumLike + From<f64>
{
  return weight*a + (1.-weight)*b;
}

License

This library is open source, licensed under the Mozilla Public License version 2.0. In summary, you may include this source code as-is in both open-source and proprietary projects without requesting permission from me, but if you modify the source code from this library then you must make your modified version of this library available under an open-source license.

Dependencies

~1.5MB
~37K SLoC