summaryrefslogtreecommitdiffstats
path: root/futures/src/command.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-05 04:14:26 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-05 04:14:26 +0100
commitca213922d043a5532d9ab352c0d54bfca7563871 (patch)
treeee4ce50991d974144e23030d31ffb11b975cb603 /futures/src/command.rs
parent9a06e481b7f52a9d8e123c909d5614332f607c53 (diff)
downloadiced-ca213922d043a5532d9ab352c0d54bfca7563871.tar.gz
iced-ca213922d043a5532d9ab352c0d54bfca7563871.tar.bz2
iced-ca213922d043a5532d9ab352c0d54bfca7563871.zip
Drop `Send` in `Command` and `Executor` on Wasm
Diffstat (limited to 'futures/src/command.rs')
-rw-r--r--futures/src/command.rs105
1 files changed, 8 insertions, 97 deletions
diff --git a/futures/src/command.rs b/futures/src/command.rs
index e7885fb8..26f58fde 100644
--- a/futures/src/command.rs
+++ b/futures/src/command.rs
@@ -1,100 +1,11 @@
-use futures::future::{BoxFuture, Future, FutureExt};
+#[cfg(not(target_arch = "wasm32"))]
+mod native;
-/// A collection of async operations.
-///
-/// You should be able to turn a future easily into a [`Command`], either by
-/// using the `From` trait or [`Command::perform`].
-///
-/// [`Command`]: struct.Command.html
-pub struct Command<T> {
- futures: Vec<BoxFuture<'static, T>>,
-}
+#[cfg(not(target_arch = "wasm32"))]
+pub use native::Command;
-impl<T> Command<T> {
- /// Creates an empty [`Command`].
- ///
- /// In other words, a [`Command`] that does nothing.
- ///
- /// [`Command`]: struct.Command.html
- pub fn none() -> Self {
- Self {
- futures: Vec::new(),
- }
- }
+#[cfg(target_arch = "wasm32")]
+mod web;
- /// Creates a [`Command`] that performs the action of the given future.
- ///
- /// [`Command`]: struct.Command.html
- pub fn perform<A>(
- future: impl Future<Output = T> + 'static + Send,
- f: impl Fn(T) -> A + 'static + Send,
- ) -> Command<A> {
- Command {
- futures: vec![future.map(f).boxed()],
- }
- }
-
- /// Applies a transformation to the result of a [`Command`].
- ///
- /// [`Command`]: struct.Command.html
- pub fn map<A>(
- mut self,
- f: impl Fn(T) -> A + 'static + Send + Sync,
- ) -> Command<A>
- where
- T: 'static,
- {
- let f = std::sync::Arc::new(f);
-
- Command {
- futures: self
- .futures
- .drain(..)
- .map(|future| {
- let f = f.clone();
-
- future.map(move |result| f(result)).boxed()
- })
- .collect(),
- }
- }
-
- /// Creates a [`Command`] that performs the actions of all the given
- /// commands.
- ///
- /// Once this command is run, all the commands will be exectued at once.
- ///
- /// [`Command`]: struct.Command.html
- pub fn batch(commands: impl IntoIterator<Item = Command<T>>) -> Self {
- Self {
- futures: commands
- .into_iter()
- .flat_map(|command| command.futures)
- .collect(),
- }
- }
-
- /// Converts a [`Command`] into its underlying list of futures.
- ///
- /// [`Command`]: struct.Command.html
- pub fn futures(self) -> Vec<BoxFuture<'static, T>> {
- self.futures
- }
-}
-
-impl<T, A> From<A> for Command<T>
-where
- A: Future<Output = T> + 'static + Send,
-{
- fn from(future: A) -> Self {
- Self {
- futures: vec![future.boxed()],
- }
- }
-}
-
-impl<T> std::fmt::Debug for Command<T> {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("Command").finish()
- }
-}
+#[cfg(target_arch = "wasm32")]
+pub use web::Command;