From d9f24dddb984307127135d5ef0f1b4cd7af98360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 6 Sep 2025 17:07:24 +0200 Subject: [PATCH] Add a pure `now` helper to `time` module --- src/time.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/time.rs b/src/time.rs index f32eeb17..6400dc7f 100644 --- a/src/time.rs +++ b/src/time.rs @@ -11,3 +11,17 @@ pub use crate::core::time::*; ))) )] pub use iced_futures::backend::default::time::*; + +use crate::Task; + +/// Returns a [`Task`] that produces the current [`Instant`] +/// by calling [`Instant::now`]. +/// +/// While you can call [`Instant::now`] directly in your application, +/// this is an "impure" operation (i.e. it's not referentially transparent). +/// +/// You may care about purity if you want to leverage the `time-travel` +/// feature properly. +pub fn now() -> Task { + Task::future(async { Instant::now() }) +}