Relax Fn trait bounds in Command & Action
This commit is contained in:
parent
e209349c50
commit
f21d1209aa
6 changed files with 12 additions and 12 deletions
|
|
@ -41,7 +41,7 @@ impl<T> Command<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a transformation to the result of a [`Command`].
|
/// Applies a transformation to the result of a [`Command`].
|
||||||
pub fn map<A>(self, f: impl Fn(T) -> A) -> Command<A>
|
pub fn map<A>(self, mut f: impl FnMut(T) -> A) -> Command<A>
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: 'static,
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ impl Clipboard for Null {
|
||||||
/// [`Command`]: crate::Command
|
/// [`Command`]: crate::Command
|
||||||
pub enum Action<T> {
|
pub enum Action<T> {
|
||||||
/// Read the clipboard and produce `T` with the result.
|
/// Read the clipboard and produce `T` with the result.
|
||||||
Read(Box<dyn Fn(Option<String>) -> T>),
|
Read(Box<dyn FnOnce(Option<String>) -> T>),
|
||||||
|
|
||||||
/// Write the given contents to the clipboard.
|
/// Write the given contents to the clipboard.
|
||||||
Write(String),
|
Write(String),
|
||||||
|
|
@ -40,7 +40,7 @@ impl<T> Action<T> {
|
||||||
/// Maps the output of a clipboard [`Action`] using the provided closure.
|
/// Maps the output of a clipboard [`Action`] using the provided closure.
|
||||||
pub fn map<A>(
|
pub fn map<A>(
|
||||||
self,
|
self,
|
||||||
f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
|
f: impl FnOnce(T) -> A + 'static + MaybeSend + Sync,
|
||||||
) -> Action<A>
|
) -> Action<A>
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: 'static,
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ impl<T> Command<T> {
|
||||||
/// Creates a [`Command`] that performs the action of the given future.
|
/// Creates a [`Command`] that performs the action of the given future.
|
||||||
pub fn perform<A>(
|
pub fn perform<A>(
|
||||||
future: impl Future<Output = T> + 'static + MaybeSend,
|
future: impl Future<Output = T> + 'static + MaybeSend,
|
||||||
f: impl Fn(T) -> A + 'static + MaybeSend,
|
f: impl FnOnce(T) -> A + 'static + MaybeSend,
|
||||||
) -> Command<A> {
|
) -> Command<A> {
|
||||||
use iced_futures::futures::FutureExt;
|
use iced_futures::futures::FutureExt;
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ impl<T> Command<T> {
|
||||||
/// Applies a transformation to the result of a [`Command`].
|
/// Applies a transformation to the result of a [`Command`].
|
||||||
pub fn map<A>(
|
pub fn map<A>(
|
||||||
self,
|
self,
|
||||||
f: impl Fn(T) -> A + 'static + MaybeSend + Sync + Clone,
|
f: impl FnMut(T) -> A + 'static + MaybeSend + Sync + Clone,
|
||||||
) -> Command<A>
|
) -> Command<A>
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: 'static,
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ impl<T> Action<T> {
|
||||||
/// [`Command`]: crate::Command
|
/// [`Command`]: crate::Command
|
||||||
pub fn map<A>(
|
pub fn map<A>(
|
||||||
self,
|
self,
|
||||||
f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
|
f: impl FnMut(T) -> A + 'static + MaybeSend + Sync,
|
||||||
) -> Action<A>
|
) -> Action<A>
|
||||||
where
|
where
|
||||||
A: 'static,
|
A: 'static,
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,15 @@ pub enum Action<T> {
|
||||||
QueryInformation(Box<dyn Closure<T>>),
|
QueryInformation(Box<dyn Closure<T>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Closure<T>: Fn(system::Information) -> T + MaybeSend {}
|
pub trait Closure<T>: FnOnce(system::Information) -> T + MaybeSend {}
|
||||||
|
|
||||||
impl<T, O> Closure<O> for T where T: Fn(system::Information) -> O + MaybeSend {}
|
impl<T, O> Closure<O> for T where T: FnOnce(system::Information) -> O + MaybeSend {}
|
||||||
|
|
||||||
impl<T> Action<T> {
|
impl<T> Action<T> {
|
||||||
/// Maps the output of a system [`Action`] using the provided closure.
|
/// Maps the output of a system [`Action`] using the provided closure.
|
||||||
pub fn map<A>(
|
pub fn map<A>(
|
||||||
self,
|
self,
|
||||||
f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
|
f: impl FnOnce(T) -> A + 'static + MaybeSend + Sync,
|
||||||
) -> Action<A>
|
) -> Action<A>
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: 'static,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ impl<T> Action<T> {
|
||||||
/// Maps the output of an [`Action`] using the given function.
|
/// Maps the output of an [`Action`] using the given function.
|
||||||
pub fn map<A>(
|
pub fn map<A>(
|
||||||
self,
|
self,
|
||||||
f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
|
f: impl FnMut(T) -> A + 'static + MaybeSend + Sync,
|
||||||
) -> Action<A>
|
) -> Action<A>
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: 'static,
|
||||||
|
|
@ -37,7 +37,7 @@ impl<T> Action<T> {
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
struct Map<A, B> {
|
struct Map<A, B> {
|
||||||
operation: Box<dyn Operation<A>>,
|
operation: Box<dyn Operation<A>>,
|
||||||
f: Box<dyn Fn(A) -> B>,
|
f: Box<dyn FnMut(A) -> B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A, B> Operation<B> for Map<A, B>
|
impl<A, B> Operation<B> for Map<A, B>
|
||||||
|
|
@ -52,7 +52,7 @@ where
|
||||||
) {
|
) {
|
||||||
struct MapRef<'a, A, B> {
|
struct MapRef<'a, A, B> {
|
||||||
operation: &'a mut dyn Operation<A>,
|
operation: &'a mut dyn Operation<A>,
|
||||||
f: &'a dyn Fn(A) -> B,
|
f: &'a mut dyn FnMut(A) -> B,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, B> Operation<B> for MapRef<'a, A, B> {
|
impl<'a, A, B> Operation<B> for MapRef<'a, A, B> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue