Skip to content

Commit 7a821ac

Browse files
authored
Merge pull request #1147 from vladov3000/impl-sum-trait-for-point
implement sum trait for point
2 parents bc5f8b9 + 9c9c866 commit 7a821ac

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/sdl2/rect.rs

+12
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,12 @@ impl DivAssign<i32> for Point {
891891
}
892892
}
893893

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+
894900
#[cfg(test)]
895901
mod test {
896902
use super::{max_int_value, min_int_value, Point, Rect};
@@ -1096,4 +1102,10 @@ mod test {
10961102
point /= 3;
10971103
assert_eq!(point, Point::new(-11, 5) / 3);
10981104
}
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+
}
10991111
}

0 commit comments

Comments
 (0)