diff options
| author | Ulf Lilleengen <[email protected]> | 2025-08-18 08:00:10 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-18 08:00:10 +0000 |
| commit | a5cb04bdab602bc3bd056d254a9d61cad55bd967 (patch) | |
| tree | 3a51ddc6f6eaca4ab82d18cf62353d517f1b8de7 | |
| parent | bfe4395b3b9792bb79363e2f32a9ab7bf69bb78d (diff) | |
| parent | 1b246d77c9972706285193b7a17ae0f5543e5a34 (diff) | |
Merge pull request #4561 from mkj/pr/duration-sum
time: implement Sum for Duration
| -rw-r--r-- | embassy-time/CHANGELOG.md | 1 | ||||
| -rw-r--r-- | embassy-time/src/duration.rs | 9 |
2 files changed, 10 insertions, 0 deletions
diff --git a/embassy-time/CHANGELOG.md b/embassy-time/CHANGELOG.md index a0c1abe8d..2e94e0112 100644 --- a/embassy-time/CHANGELOG.md +++ b/embassy-time/CHANGELOG.md | |||
| @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| 15 | - Don't select `critical-section` impl for `std` | 15 | - Don't select `critical-section` impl for `std` |
| 16 | - Manually implement the future for `with_timeout` | 16 | - Manually implement the future for `with_timeout` |
| 17 | - Add 133MHz tick rate to support PR2040 @ 133MHz when `TIMERx`'s `SOURCE` is set to `SYSCLK` | 17 | - Add 133MHz tick rate to support PR2040 @ 133MHz when `TIMERx`'s `SOURCE` is set to `SYSCLK` |
| 18 | - Implement Sum for Duration | ||
| 18 | 19 | ||
| 19 | ## 0.4.0 - 2025-01-02 | 20 | ## 0.4.0 - 2025-01-02 |
| 20 | 21 | ||
diff --git a/embassy-time/src/duration.rs b/embassy-time/src/duration.rs index dcda705d3..5b140eeff 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs | |||
| @@ -293,3 +293,12 @@ impl From<Duration> for core::time::Duration { | |||
| 293 | core::time::Duration::from_micros(value.as_micros()) | 293 | core::time::Duration::from_micros(value.as_micros()) |
| 294 | } | 294 | } |
| 295 | } | 295 | } |
| 296 | |||
| 297 | impl core::iter::Sum for Duration { | ||
| 298 | fn sum<I>(iter: I) -> Self | ||
| 299 | where | ||
| 300 | I: Iterator<Item = Duration>, | ||
| 301 | { | ||
| 302 | Duration::from_ticks(iter.map(|d| d.as_ticks()).sum()) | ||
| 303 | } | ||
| 304 | } | ||
