mutils/num/
num.rs

1use std::fmt::Debug;
2use std::fmt::Display;
3use std::ops::Add;
4use std::ops::AddAssign;
5use std::ops::Div;
6use std::ops::DivAssign;
7use std::ops::Mul;
8use std::ops::MulAssign;
9use std::ops::Rem;
10use std::ops::Shl;
11use std::ops::ShlAssign;
12use std::ops::Shr;
13use std::ops::ShrAssign;
14use std::ops::Sub;
15use std::ops::SubAssign;
16
17use super::Half;
18use super::NumTrampolene;
19use crate::num::FromRounded;
20use crate::num::NumIdentity;
21use crate::num::ToRounded;
22
23/// A common number trait.
24///
25/// A number is a collection of the traits below.
26/// But you cannot get them all together in Rust.
27/// So we have had to build our own.
28///
29/// The Points, Rects, and Shapes, all use these traits.
30pub trait Num:
31    Add<Self, Output = Self>
32    + AddAssign
33    + Sub<Self, Output = Self>
34    + SubAssign
35    + Mul<Self, Output = Self>
36    + MulAssign
37    + Div<Self, Output = Self>
38    + DivAssign
39    + Rem<Self, Output = Self>
40    + PartialOrd
41    + Display
42    + Copy
43    + PartialEq
44    + NumTrampolene
45    + Half
46    + NumIdentity
47    + Sized
48    + Debug
49    + ToRounded<f32>
50    + FromRounded<f32>
51{
52}
53
54/// You might be wondering 'what does this do?'
55/// So am I!
56///
57/// I think it's saying *'the trait above really does exists, and is
58/// implemented, for every type that implements Add + AddAssign + Sub, etc.
59impl<U> Num for U
60where
61    U: Add<Self, Output = Self>
62        + AddAssign
63        + Sub<Self, Output = Self>
64        + SubAssign
65        + Mul<Self, Output = Self>
66        + MulAssign
67        + Div<Self, Output = Self>
68        + DivAssign
69        + Rem<Self, Output = Self>
70        + PartialOrd
71        + Display
72        + Copy
73        + PartialEq
74        + NumTrampolene
75        + Half
76        + NumIdentity
77        + Sized
78        + Debug
79        + ToRounded<f32>,
80    f32: ToRounded<Self>,
81{
82}
83
84/// A common number trait.
85///
86/// A number is a collection of the traits below.
87/// But you cannot get them all together in Rust.
88/// So we have had to build our own.
89///
90/// The Points, Rects, and Shapes, all use these traits.
91pub trait INum:
92    Num + Shl<Self, Output = Self> + ShlAssign + Shr<Self, Output = Self> + ShrAssign
93{
94}
95
96/// You might be wondering 'what does this do?'
97/// So am I!
98///
99/// I think it's saying *'the trait above really does exists, and is
100/// implemented, for `U`'*. This applies for cases where `U` matches the `Num`
101/// trait.
102impl<U> INum for U where
103    U: Num + Shl<Self, Output = Self> + ShlAssign + Shr<Self, Output = Self> + ShrAssign
104{
105}