65 Zeilen
1,9 KiB
Rust
65 Zeilen
1,9 KiB
Rust
use num::*;
|
|
|
|
use crate::predefined_const;
|
|
|
|
use super::Kartesian;
|
|
|
|
macro_rules! to_coords_impl {
|
|
($subtype:ident) => {
|
|
impl ToCoords for Kartesian<$subtype> {
|
|
fn to_coords(self) -> Kartesian<usize> {
|
|
Kartesian { x: self.x as usize, y: self.y as usize }
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
pub trait CheckedBasicMath: CheckedAdd + CheckedSub {}
|
|
impl<T: CheckedAdd + CheckedSub> 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<usize>;
|
|
}
|
|
|
|
to_coords_impl!(u8);
|
|
to_coords_impl!(u16);
|
|
to_coords_impl!(u32);
|
|
to_coords_impl!(u64);
|
|
to_coords_impl!(u128);
|
|
|
|
impl ToCoords for Kartesian<usize> {
|
|
fn to_coords(self) -> Kartesian<usize> {
|
|
Kartesian { x: self.x, y: self.y }
|
|
}
|
|
}
|