From f21d1209aa576a3e597c100fa56afe554dc2babd Mon Sep 17 00:00:00 2001 From: 无限UCW Date: Fri, 12 Aug 2022 01:57:05 +0800 Subject: Relax `Fn` trait bounds in `Command` & `Action` --- native/src/clipboard.rs | 4 ++-- native/src/command.rs | 4 ++-- native/src/command/action.rs | 2 +- native/src/system/action.rs | 6 +++--- native/src/widget/action.rs | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'native') diff --git a/native/src/clipboard.rs b/native/src/clipboard.rs index c9105bc0..6a77334c 100644 --- a/native/src/clipboard.rs +++ b/native/src/clipboard.rs @@ -30,7 +30,7 @@ impl Clipboard for Null { /// [`Command`]: crate::Command pub enum Action { /// Read the clipboard and produce `T` with the result. - Read(Box) -> T>), + Read(Box) -> T>), /// Write the given contents to the clipboard. Write(String), @@ -40,7 +40,7 @@ impl Action { /// Maps the output of a clipboard [`Action`] using the provided closure. pub fn map( self, - f: impl Fn(T) -> A + 'static + MaybeSend + Sync, + f: impl FnOnce(T) -> A + 'static + MaybeSend + Sync, ) -> Action where T: 'static, diff --git a/native/src/command.rs b/native/src/command.rs index b0b12805..3571efc4 100644 --- a/native/src/command.rs +++ b/native/src/command.rs @@ -36,7 +36,7 @@ impl Command { /// Creates a [`Command`] that performs the action of the given future. pub fn perform( future: impl Future + 'static + MaybeSend, - f: impl Fn(T) -> A + 'static + MaybeSend, + f: impl FnOnce(T) -> A + 'static + MaybeSend, ) -> Command { use iced_futures::futures::FutureExt; @@ -56,7 +56,7 @@ impl Command { /// Applies a transformation to the result of a [`Command`]. pub fn map( self, - f: impl Fn(T) -> A + 'static + MaybeSend + Sync + Clone, + f: impl FnMut(T) -> A + 'static + MaybeSend + Sync + Clone, ) -> Command where T: 'static, diff --git a/native/src/command/action.rs b/native/src/command/action.rs index 3fb02899..549632dd 100644 --- a/native/src/command/action.rs +++ b/native/src/command/action.rs @@ -35,7 +35,7 @@ impl Action { /// [`Command`]: crate::Command pub fn map( self, - f: impl Fn(T) -> A + 'static + MaybeSend + Sync, + f: impl FnMut(T) -> A + 'static + MaybeSend + Sync, ) -> Action where A: 'static, diff --git a/native/src/system/action.rs b/native/src/system/action.rs index dea9536f..7f66141b 100644 --- a/native/src/system/action.rs +++ b/native/src/system/action.rs @@ -9,15 +9,15 @@ pub enum Action { QueryInformation(Box>), } -pub trait Closure: Fn(system::Information) -> T + MaybeSend {} +pub trait Closure: FnOnce(system::Information) -> T + MaybeSend {} -impl Closure for T where T: Fn(system::Information) -> O + MaybeSend {} +impl Closure for T where T: FnOnce(system::Information) -> O + MaybeSend {} impl Action { /// Maps the output of a system [`Action`] using the provided closure. pub fn map( self, - f: impl Fn(T) -> A + 'static + MaybeSend + Sync, + f: impl FnOnce(T) -> A + 'static + MaybeSend + Sync, ) -> Action where T: 'static, diff --git a/native/src/widget/action.rs b/native/src/widget/action.rs index 766e902b..ea1d9b12 100644 --- a/native/src/widget/action.rs +++ b/native/src/widget/action.rs @@ -16,7 +16,7 @@ impl Action { /// Maps the output of an [`Action`] using the given function. pub fn map( self, - f: impl Fn(T) -> A + 'static + MaybeSend + Sync, + f: impl FnMut(T) -> A + 'static + MaybeSend + Sync, ) -> Action where T: 'static, @@ -37,7 +37,7 @@ impl Action { #[allow(missing_debug_implementations)] struct Map { operation: Box>, - f: Box B>, + f: Box B>, } impl Operation for Map @@ -52,7 +52,7 @@ where ) { struct MapRef<'a, A, B> { operation: &'a mut dyn Operation, - f: &'a dyn Fn(A) -> B, + f: &'a mut dyn FnMut(A) -> B, } impl<'a, A, B> Operation for MapRef<'a, A, B> { -- cgit From 23229e00f608585bf2d623709a4240296721777d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 17 Aug 2022 15:54:31 +0200 Subject: Use `FnOnce` in `Command::perform` ... and revert `FnMut` usage. --- native/src/clipboard.rs | 4 ++-- native/src/command.rs | 2 +- native/src/command/action.rs | 2 +- native/src/system/action.rs | 6 +++--- native/src/widget/action.rs | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'native') diff --git a/native/src/clipboard.rs b/native/src/clipboard.rs index 6a77334c..c9105bc0 100644 --- a/native/src/clipboard.rs +++ b/native/src/clipboard.rs @@ -30,7 +30,7 @@ impl Clipboard for Null { /// [`Command`]: crate::Command pub enum Action { /// Read the clipboard and produce `T` with the result. - Read(Box) -> T>), + Read(Box) -> T>), /// Write the given contents to the clipboard. Write(String), @@ -40,7 +40,7 @@ impl Action { /// Maps the output of a clipboard [`Action`] using the provided closure. pub fn map( self, - f: impl FnOnce(T) -> A + 'static + MaybeSend + Sync, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync, ) -> Action where T: 'static, diff --git a/native/src/command.rs b/native/src/command.rs index 3571efc4..89ee7375 100644 --- a/native/src/command.rs +++ b/native/src/command.rs @@ -56,7 +56,7 @@ impl Command { /// Applies a transformation to the result of a [`Command`]. pub fn map( self, - f: impl FnMut(T) -> A + 'static + MaybeSend + Sync + Clone, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync + Clone, ) -> Command where T: 'static, diff --git a/native/src/command/action.rs b/native/src/command/action.rs index 549632dd..3fb02899 100644 --- a/native/src/command/action.rs +++ b/native/src/command/action.rs @@ -35,7 +35,7 @@ impl Action { /// [`Command`]: crate::Command pub fn map( self, - f: impl FnMut(T) -> A + 'static + MaybeSend + Sync, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync, ) -> Action where A: 'static, diff --git a/native/src/system/action.rs b/native/src/system/action.rs index 7f66141b..dea9536f 100644 --- a/native/src/system/action.rs +++ b/native/src/system/action.rs @@ -9,15 +9,15 @@ pub enum Action { QueryInformation(Box>), } -pub trait Closure: FnOnce(system::Information) -> T + MaybeSend {} +pub trait Closure: Fn(system::Information) -> T + MaybeSend {} -impl Closure for T where T: FnOnce(system::Information) -> O + MaybeSend {} +impl Closure for T where T: Fn(system::Information) -> O + MaybeSend {} impl Action { /// Maps the output of a system [`Action`] using the provided closure. pub fn map( self, - f: impl FnOnce(T) -> A + 'static + MaybeSend + Sync, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync, ) -> Action where T: 'static, diff --git a/native/src/widget/action.rs b/native/src/widget/action.rs index ea1d9b12..766e902b 100644 --- a/native/src/widget/action.rs +++ b/native/src/widget/action.rs @@ -16,7 +16,7 @@ impl Action { /// Maps the output of an [`Action`] using the given function. pub fn map( self, - f: impl FnMut(T) -> A + 'static + MaybeSend + Sync, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync, ) -> Action where T: 'static, @@ -37,7 +37,7 @@ impl Action { #[allow(missing_debug_implementations)] struct Map { operation: Box>, - f: Box B>, + f: Box B>, } impl Operation for Map @@ -52,7 +52,7 @@ where ) { struct MapRef<'a, A, B> { operation: &'a mut dyn Operation, - f: &'a mut dyn FnMut(A) -> B, + f: &'a dyn Fn(A) -> B, } impl<'a, A, B> Operation for MapRef<'a, A, B> { -- cgit