summaryrefslogtreecommitdiff
path: root/src/internal.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2023-12-24 20:03:12 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2023-12-24 21:38:49 +1300
commit8547ad9c2f2867da9b0e655dd4ff0fe78f04ffba (patch)
tree554f4514177cc8c1436ed3ec3ae44f176684f664 /src/internal.rs
downloadgeometry-8547ad9c2f2867da9b0e655dd4ff0fe78f04ffba.zip
First commitHEADv1.0.0main
Diffstat (limited to 'src/internal.rs')
-rw-r--r--src/internal.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/internal.rs b/src/internal.rs
new file mode 100644
index 0000000..166e25f
--- /dev/null
+++ b/src/internal.rs
@@ -0,0 +1,47 @@
+use std::fmt;
+use std::ops::{Add, Sub, AddAssign, SubAssign, Mul, MulAssign, Div, DivAssign};
+
+pub trait Internal:
+ Copy + Clone + PartialEq + fmt::Debug + fmt::Display + PartialOrd +
+ Add<Output=Self> + Sub<Output=Self> + AddAssign + SubAssign +
+ Mul<Output=Self> + MulAssign + Div<Output=Self> + DivAssign +
+{
+ const ZERO: Self;
+
+ fn as_usize(&self) -> usize;
+
+ fn as_f64(&self) -> f64;
+}
+
+macro_rules! impl_for_type {
+ ($z:expr, $t:ty) => {
+ impl Internal for $t {
+ const ZERO: Self = $z;
+
+ fn as_usize(&self) -> usize {
+ *self as usize
+ }
+
+ fn as_f64(&self) -> f64 {
+ *self as f64
+ }
+ }
+ };
+}
+
+impl_for_type!(0, u8);
+impl_for_type!(0, u16);
+impl_for_type!(0, u32);
+impl_for_type!(0, u64);
+impl_for_type!(0, u128);
+impl_for_type!(0, usize);
+
+impl_for_type!(0, i8);
+impl_for_type!(0, i16);
+impl_for_type!(0, i32);
+impl_for_type!(0, i64);
+impl_for_type!(0, i128);
+impl_for_type!(0, isize);
+
+impl_for_type!(0.0, f32);
+impl_for_type!(0.0, f64);