We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents bc5f8b9 + 9c9c866 commit 7a821acCopy full SHA for 7a821ac
src/sdl2/rect.rs
@@ -891,6 +891,12 @@ impl DivAssign<i32> for Point {
891
}
892
893
894
+impl std::iter::Sum for Point {
895
+ fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
896
+ iter.fold(Point::new(0, 0), Point::add)
897
+ }
898
+}
899
+
900
#[cfg(test)]
901
mod test {
902
use super::{max_int_value, min_int_value, Point, Rect};
@@ -1096,4 +1102,10 @@ mod test {
1096
1102
point /= 3;
1097
1103
assert_eq!(point, Point::new(-11, 5) / 3);
1098
1104
1105
1106
+ #[test]
1107
+ fn point_sum() {
1108
+ let points_sum: Point = vec![Point::new(-11, 5), Point::new(6, 2)].into_iter().sum();
1109
+ assert_eq!(Point::new(-5, 7), points_sum);
1110
1099
1111
0 commit comments