use num::*; use crate::predefined_const; use super::Kartesian; /// implements an method that turns an Kartesian of all sizes into Coordinates macro_rules! to_coords_impl { ($subtype:ident) => { impl ToCoords for Kartesian<$subtype> { fn to_coords(self) -> Kartesian { Kartesian { x: self.x as usize, y: self.y as usize, } } } }; } pub trait CheckedBasicMath: CheckedAdd + CheckedSub {} impl CheckedBasicMath for T {} pub trait MaximumValue { const MAX: Self; } predefined_const!(MaximumValue, MAX, u8); predefined_const!(MaximumValue, MAX, u16); predefined_const!(MaximumValue, MAX, u32); predefined_const!(MaximumValue, MAX, u64); predefined_const!(MaximumValue, MAX, u128); predefined_const!(MaximumValue, MAX, usize); predefined_const!(MaximumValue, MAX, i8); predefined_const!(MaximumValue, MAX, i16); predefined_const!(MaximumValue, MAX, i32); predefined_const!(MaximumValue, MAX, i64); predefined_const!(MaximumValue, MAX, i128); predefined_const!(MaximumValue, MAX, isize); pub trait MinimumValue { const MIN: Self; } predefined_const!(MinimumValue, MIN, u8); predefined_const!(MinimumValue, MIN, u16); predefined_const!(MinimumValue, MIN, u32); predefined_const!(MinimumValue, MIN, u64); predefined_const!(MinimumValue, MIN, u128); predefined_const!(MinimumValue, MIN, usize); predefined_const!(MinimumValue, MIN, i8); predefined_const!(MinimumValue, MIN, i16); predefined_const!(MinimumValue, MIN, i32); predefined_const!(MinimumValue, MIN, i64); predefined_const!(MinimumValue, MIN, i128); predefined_const!(MinimumValue, MIN, isize); pub trait ToCoords: Copy { fn to_coords(self) -> Kartesian; } to_coords_impl!(u8); to_coords_impl!(u16); to_coords_impl!(u32); to_coords_impl!(u64); to_coords_impl!(u128); impl ToCoords for Kartesian { fn to_coords(self) -> Kartesian { self } }