From 1b246d77c9972706285193b7a17ae0f5543e5a34 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 16 Aug 2025 22:40:04 +0800 Subject: time: implement Sum for Duration --- embassy-time/CHANGELOG.md | 1 + embassy-time/src/duration.rs | 9 +++++++++ 2 files changed, 10 insertions(+) (limited to 'embassy-time') 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 - Don't select `critical-section` impl for `std` - Manually implement the future for `with_timeout` - Add 133MHz tick rate to support PR2040 @ 133MHz when `TIMERx`'s `SOURCE` is set to `SYSCLK` +- Implement Sum for Duration ## 0.4.0 - 2025-01-02 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 for core::time::Duration { core::time::Duration::from_micros(value.as_micros()) } } + +impl core::iter::Sum for Duration { + fn sum(iter: I) -> Self + where + I: Iterator, + { + Duration::from_ticks(iter.map(|d| d.as_ticks()).sum()) + } +} -- cgit