summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-11 03:39:42 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-11 03:41:29 +0100
commit0c528be2ea74f9aae1d4ac80b282ba9c16674649 (patch)
tree87108ca5917382a8e6a7d53968896f5ee1f7a617 /runtime
parent9f21eae1528fa414adbfb987ce4c851fa58326fe (diff)
downloadiced-0c528be2ea74f9aae1d4ac80b282ba9c16674649.tar.gz
iced-0c528be2ea74f9aae1d4ac80b282ba9c16674649.tar.bz2
iced-0c528be2ea74f9aae1d4ac80b282ba9c16674649.zip
Introduce `with` helper and use `sipper` in `gallery` example
Diffstat (limited to 'runtime')
-rw-r--r--runtime/src/task.rs46
1 files changed, 1 insertions, 45 deletions
diff --git a/runtime/src/task.rs b/runtime/src/task.rs
index 1a1ef699..022483f7 100644
--- a/runtime/src/task.rs
+++ b/runtime/src/task.rs
@@ -63,7 +63,7 @@ impl<T> Task<T> {
/// progress with the first closure and the output with the second one.
pub fn sip<S>(
sipper: S,
- on_progress: impl Fn(S::Progress) -> T + MaybeSend + 'static,
+ on_progress: impl FnMut(S::Progress) -> T + MaybeSend + 'static,
on_output: impl FnOnce(<S as Future>::Output) -> T + MaybeSend + 'static,
) -> Self
where
@@ -98,50 +98,6 @@ impl<T> Task<T> {
self.then(move |output| Task::done(f(output)))
}
- /// Combines a prefix value with the result of the [`Task`] using
- /// the provided closure.
- ///
- /// Sometimes you will want to identify the source or target
- /// of some [`Task`] in your UI. This can be achieved through
- /// normal means by using [`map`]:
- ///
- /// ```rust
- /// # use iced_runtime::Task;
- /// # let task = Task::none();
- /// # enum Message { TaskCompleted(u32, ()) }
- /// let id = 123;
- ///
- /// # let _ = {
- /// task.map(move |result| Message::TaskCompleted(id, result))
- /// # };
- /// ```
- ///
- /// Quite a mouthful. [`map_with`] lets you write:
- ///
- /// ```rust
- /// # use iced_runtime::Task;
- /// # let task = Task::none();
- /// # enum Message { TaskCompleted(u32, ()) }
- /// # let id = 123;
- /// # let _ = {
- /// task.map_with(id, Message::TaskCompleted)
- /// # };
- /// ```
- ///
- /// Much nicer!
- pub fn map_with<P, O>(
- self,
- prefix: P,
- mut f: impl FnMut(P, T) -> O + MaybeSend + 'static,
- ) -> Task<O>
- where
- T: MaybeSend + 'static,
- P: MaybeSend + Clone + 'static,
- O: MaybeSend + 'static,
- {
- self.map(move |result| f(prefix.clone(), result))
- }
-
/// Performs a new [`Task`] for every output of the current [`Task`] using the
/// given closure.
///