simple_si_units_core/
lib.rs

1#![no_std]
2#![warn(missing_docs)]
3#![ doc = include_str!("../README.md")]
4use core::fmt::{Debug, Display};
5
6/// The `NumLike` trait is just a shorthand definition for any "number-like" 
7/// type in Rust. "Number-like" means that a type implements the traits for 
8/// standard arithmatic (Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, 
9/// DivAssign, and Neg), plus Clone, Debug, and Display. Most number types also
10/// implement the Copy marker trait, but that is not required (for example, an 
11/// arbitrary-precision number type must dynamically allocate memory and thus 
12/// cannot implement Copy).
13/// 
14/// This trait is not meant to be implemented, just for making generic type 
15/// templates more ergonomic. E.g.
16/// ```rust
17/// use simple_si_units_core::NumLike;
18/// 
19/// fn delta_squared<T>(a: T, b: T) -> T where T: NumLike {
20///   let delta = b - a;
21///   return delta.clone() * delta;
22/// }
23/// ```
24pub trait NumLike: core::ops::Add<Output=Self>
25+ core::ops::AddAssign
26+ core::ops::Sub<Output=Self>
27+ core::ops::SubAssign
28+ core::ops::Mul<Output=Self>
29+ core::ops::MulAssign
30+ core::ops::Div<Output=Self>
31+ core::ops::DivAssign
32+ core::ops::Neg<Output=Self>
33+ Clone
34+ Debug
35+ Display
36{}
37impl<T> NumLike for T where T: core::ops::Add<Output=Self>
38+ core::ops::AddAssign
39+ core::ops::Sub<Output=Self>
40+ core::ops::SubAssign
41+ core::ops::Mul<Output=Self>
42+ core::ops::MulAssign
43+ core::ops::Div<Output=Self>
44+ core::ops::DivAssign
45+ core::ops::Neg<Output=Self>
46+ Clone
47+ Debug
48+ Display
49{}