Skip to content

Commit

Permalink
Use FnOnce in Command::perform
Browse files Browse the repository at this point in the history
... and revert `FnMut` usage.
  • Loading branch information
hecrj committed Aug 17, 2022
1 parent f21d120 commit 23229e0
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion futures/src/command.rs
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ impl<T> Command<T> {
}

/// Applies a transformation to the result of a [`Command`].
pub fn map<A>(self, mut f: impl FnMut(T) -> A) -> Command<A>
pub fn map<A>(self, f: impl Fn(T) -> A) -> Command<A>
where
T: 'static,
{
4 changes: 2 additions & 2 deletions native/src/clipboard.rs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ impl Clipboard for Null {
/// [`Command`]: crate::Command
pub enum Action<T> {
/// Read the clipboard and produce `T` with the result.
Read(Box<dyn FnOnce(Option<String>) -> T>),
Read(Box<dyn Fn(Option<String>) -> T>),

/// Write the given contents to the clipboard.
Write(String),
@@ -40,7 +40,7 @@ impl<T> Action<T> {
/// Maps the output of a clipboard [`Action`] using the provided closure.
pub fn map<A>(
self,
f: impl FnOnce(T) -> A + 'static + MaybeSend + Sync,
f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
) -> Action<A>
where
T: 'static,
2 changes: 1 addition & 1 deletion native/src/command.rs
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ impl<T> Command<T> {
/// Applies a transformation to the result of a [`Command`].
pub fn map<A>(
self,
f: impl FnMut(T) -> A + 'static + MaybeSend + Sync + Clone,
f: impl Fn(T) -> A + 'static + MaybeSend + Sync + Clone,
) -> Command<A>
where
T: 'static,
2 changes: 1 addition & 1 deletion native/src/command/action.rs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ impl<T> Action<T> {
/// [`Command`]: crate::Command
pub fn map<A>(
self,
f: impl FnMut(T) -> A + 'static + MaybeSend + Sync,
f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
) -> Action<A>
where
A: 'static,
6 changes: 3 additions & 3 deletions native/src/system/action.rs
Original file line number Diff line number Diff line change
@@ -9,15 +9,15 @@ pub enum Action<T> {
QueryInformation(Box<dyn Closure<T>>),
}

pub trait Closure<T>: FnOnce(system::Information) -> T + MaybeSend {}
pub trait Closure<T>: Fn(system::Information) -> T + MaybeSend {}

impl<T, O> Closure<O> for T where T: FnOnce(system::Information) -> O + MaybeSend {}
impl<T, O> Closure<O> for T where T: Fn(system::Information) -> O + MaybeSend {}

impl<T> Action<T> {
/// Maps the output of a system [`Action`] using the provided closure.
pub fn map<A>(
self,
f: impl FnOnce(T) -> A + 'static + MaybeSend + Sync,
f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
) -> Action<A>
where
T: 'static,
6 changes: 3 additions & 3 deletions native/src/widget/action.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ impl<T> Action<T> {
/// Maps the output of an [`Action`] using the given function.
pub fn map<A>(
self,
f: impl FnMut(T) -> A + 'static + MaybeSend + Sync,
f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
) -> Action<A>
where
T: 'static,
@@ -37,7 +37,7 @@ impl<T> Action<T> {
#[allow(missing_debug_implementations)]
struct Map<A, B> {
operation: Box<dyn Operation<A>>,
f: Box<dyn FnMut(A) -> B>,
f: Box<dyn Fn(A) -> B>,
}

impl<A, B> Operation<B> for Map<A, B>
@@ -52,7 +52,7 @@ where
) {
struct MapRef<'a, A, B> {
operation: &'a mut dyn Operation<A>,
f: &'a mut dyn FnMut(A) -> B,
f: &'a dyn Fn(A) -> B,
}

impl<'a, A, B> Operation<B> for MapRef<'a, A, B> {

0 comments on commit 23229e0

Please sign in to comment.