From 26b261a33645f20993fd8f819109b37cabcdc67c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 14 Dec 2025 11:47:15 -0700 Subject: [PATCH] Implement Sum trait for Pixels (#44809) This adds implementations of `std::iter::Sum` for `Pixels`, allowing the use of `.sum()` on iterators of `Pixels` values. ### Changes - Implement `Sum` for `Pixels` (owned values) - Implement `Sum<&Pixels>` for `Pixels` (references) This enables ergonomic patterns like: ```rust let total: Pixels = pixel_values.iter().sum(); ``` --- crates/gpui/src/geometry.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rs index f466624dfb91af9b4a33421ea15827ebe2559665..fc735ba5e0e7e719ed12b6b1b168ec3ee49e22bb 100644 --- a/crates/gpui/src/geometry.rs +++ b/crates/gpui/src/geometry.rs @@ -2648,6 +2648,18 @@ impl Debug for Pixels { } } +impl std::iter::Sum for Pixels { + fn sum>(iter: I) -> Self { + iter.fold(Self::ZERO, |a, b| a + b) + } +} + +impl<'a> std::iter::Sum<&'a Pixels> for Pixels { + fn sum>(iter: I) -> Self { + iter.fold(Self::ZERO, |a, b| a + *b) + } +} + impl TryFrom<&'_ str> for Pixels { type Error = anyhow::Error;