From 515772c9f8eeaa318bad52fd04caba4da69b075e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 15 Aug 2024 01:30:24 +0200 Subject: [PATCH] Rename `operation::chain` to `then` ... and make `focus_*` operations generic over the output type. --- core/src/widget/operation.rs | 4 ++-- core/src/widget/operation/focusable.rs | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/widget/operation.rs b/core/src/widget/operation.rs index 741e1a5f2f..4ee4b4a714 100644 --- a/core/src/widget/operation.rs +++ b/core/src/widget/operation.rs @@ -295,7 +295,7 @@ where /// Chains the output of an [`Operation`] with the provided function to /// build a new [`Operation`]. -pub fn chain( +pub fn then( operation: impl Operation + 'static, f: fn(A) -> O, ) -> impl Operation @@ -361,7 +361,7 @@ where Outcome::Chain(Box::new((self.next)(value))) } Outcome::Chain(operation) => { - Outcome::Chain(Box::new(chain(operation, self.next))) + Outcome::Chain(Box::new(then(operation, self.next))) } } } diff --git a/core/src/widget/operation/focusable.rs b/core/src/widget/operation/focusable.rs index 0a6f2e9658..867c682e52 100644 --- a/core/src/widget/operation/focusable.rs +++ b/core/src/widget/operation/focusable.rs @@ -94,7 +94,10 @@ pub fn count() -> impl Operation { /// Produces an [`Operation`] that searches for the current focused widget, and /// - if found, focuses the previous focusable widget. /// - if not found, focuses the last focusable widget. -pub fn focus_previous() -> impl Operation { +pub fn focus_previous() -> impl Operation +where + T: Send + 'static, +{ struct FocusPrevious { count: Count, current: usize, @@ -128,13 +131,16 @@ pub fn focus_previous() -> impl Operation { } } - operation::chain(count(), |count| FocusPrevious { count, current: 0 }) + operation::then(count(), |count| FocusPrevious { count, current: 0 }) } /// Produces an [`Operation`] that searches for the current focused widget, and /// - if found, focuses the next focusable widget. /// - if not found, focuses the first focusable widget. -pub fn focus_next() -> impl Operation { +pub fn focus_next() -> impl Operation +where + T: Send + 'static, +{ struct FocusNext { count: Count, current: usize, @@ -162,7 +168,7 @@ pub fn focus_next() -> impl Operation { } } - operation::chain(count(), |count| FocusNext { count, current: 0 }) + operation::then(count(), |count| FocusNext { count, current: 0 }) } /// Produces an [`Operation`] that searches for the current focused widget