1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#![no_std] use core::ops::*; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct Point<A>(A); impl<A: Sub<Output = A>> Point<A> { #[inline(always)] pub fn from_origin(a: A, o: A) -> Self { Point(a-o) } } impl<A: Add<Output = A>> Add<A> for Point<A> { type Output = Self; #[inline(always)] fn add(self, other: A) -> Self { Point(self.0 + other) } } impl<A: Sub<Output = A>> Sub<A> for Point<A> { type Output = Self; #[inline(always)] fn sub(self, other: A) -> Self { Point(self.0 - other) } } impl<A: AddAssign> AddAssign<A> for Point<A> { #[inline(always)] fn add_assign(&mut self, other: A) { self.0 += other } } impl<A: SubAssign> SubAssign<A> for Point<A> { #[inline(always)] fn sub_assign(&mut self, other: A) { self.0 -= other } } impl<A: Sub<Output = A>> Sub<Self> for Point<A> { type Output = A; #[inline(always)] fn sub(self, other: Self) -> Self::Output { self.0 - other.0 } }