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

no-std simple-si-units-core

This is the shared dependencies for crate simple-si-units

21 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

#1981 in Math

Download history 44/week @ 2024-07-21 47/week @ 2024-07-28 3/week @ 2024-08-04 20/week @ 2024-08-11 20/week @ 2024-08-18 26/week @ 2024-08-25 15/week @ 2024-09-01 19/week @ 2024-09-08 17/week @ 2024-09-15 24/week @ 2024-09-22 58/week @ 2024-09-29 18/week @ 2024-10-06 56/week @ 2024-10-13 71/week @ 2024-10-20 29/week @ 2024-10-27 18/week @ 2024-11-03

178 downloads per month
Used in 6 crates (2 directly)

MPL-2.0 license

5KB

simple-si-units-core

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

Contents

Crate simple-si-units-core exports the following:

NumLike

This is an ergonomic trait bundle that combines the following:

  • std::ops::Add
  • std::ops::AddAssign
  • std::ops::Sub
  • std::ops::SubAssign
  • std::ops::Mul
  • std::ops::MulAssign
  • std::ops::Div
  • std::ops::DivAssign
  • std::ops::Neg
  • Clone
  • std::fmt::Debug
  • std::fmt::Display

Thus you can use this trait as part of a struct or function template definition, like this:

use simple_si_units_core::NumLike;
pub struct MyUnit<DT: NumLike> {
    v: DT,
}

impl<DT: NumLike> std::ops::Add<Self> for MyUnit<DT> {
    type Output = Self;
    fn add(self, rhs: Self) -> Self::Output {
        return Self { v: self.v + rhs.v };
    }
}

impl<DT: NumLike> std::ops::Sub<Self> for MyUnit<DT> {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self::Output {
        return Self { v: self.v - rhs.v };
    }
}

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.

No runtime deps