From 76698ff2b5753e637b14533650c0d28e681be3c5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Sep 2021 19:21:49 +0700 Subject: Make `Command` implementations platform-specific This allows us to introduce a platform-specific `Action` to both `iced_native` and `iced_web` and remove the `Clipboard` from `Application::update` to maintain purity. Additionally, this should let us implement further actions to let users query and modify the shell environment (e.g. window, clipboard, and more!) --- web/src/command/action.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 web/src/command/action.rs (limited to 'web/src/command') diff --git a/web/src/command/action.rs b/web/src/command/action.rs new file mode 100644 index 00000000..cf384f07 --- /dev/null +++ b/web/src/command/action.rs @@ -0,0 +1,18 @@ +pub enum Action { + Future(iced_futures::BoxFuture), +} + +impl Action { + /// Applies a transformation to the result of a [`Command`]. + #[cfg(target_arch = "wasm32")] + pub fn map(self, f: impl Fn(T) -> A + 'static) -> Action + where + T: 'static, + { + use iced_futures::futures::FutureExt; + + match self { + Self::Future(future) => Action::Future(Box::pin(future.map(f))), + } + } +} -- cgit From 01b945b9814b9dc546e783a6dab66e4f7fe49786 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 13 Sep 2021 11:22:53 +0700 Subject: Write missing docs and `Debug` implementations for `web` --- web/src/command/action.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'web/src/command') diff --git a/web/src/command/action.rs b/web/src/command/action.rs index cf384f07..c0223e50 100644 --- a/web/src/command/action.rs +++ b/web/src/command/action.rs @@ -2,6 +2,8 @@ pub enum Action { Future(iced_futures::BoxFuture), } +use std::fmt; + impl Action { /// Applies a transformation to the result of a [`Command`]. #[cfg(target_arch = "wasm32")] @@ -16,3 +18,11 @@ impl Action { } } } + +impl fmt::Debug for Action { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Future(_) => write!(f, "Action::Future"), + } + } +} -- cgit