From a9cbcad4d4493aeb699cf3f0a4546dd1e677c49b Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 7 Oct 2019 08:43:03 -0700 Subject: [PATCH] Add XY::sum and XY::product --- src/vec.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/vec.rs b/src/vec.rs index a546fd3..03b847d 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -269,6 +269,20 @@ impl + Clone> XY { } } +impl XY { + /// Returns `self.x + self.y`. + pub fn sum(self) -> T::Output { + self.fold(std::ops::Add::add) + } +} + +impl XY { + /// Returns `self.x * self.y` + pub fn product(self) -> T::Output { + self.fold(std::ops::Mul::mul) + } +} + impl XY { /// Returns a vector with the X component of self, and y=0. ///