From 0607161276805c66b8c2b382bbc2f83618d18e28 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 21 May 2024 05:12:41 +0200 Subject: [PATCH] improv: messages now automatically convert into `cosmic::app::Message` --- examples/open-dialog/src/main.rs | 6 ++---- src/command/mod.rs | 14 ++++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/open-dialog/src/main.rs b/examples/open-dialog/src/main.rs index 8cc01b85..c51d2f6c 100644 --- a/examples/open-dialog/src/main.rs +++ b/examples/open-dialog/src/main.rs @@ -139,8 +139,7 @@ impl cosmic::Application for App { // Send this back to the application. Message::FileRead(url, contents) - }) - .map(Into::into); + }); } // Creates a new open dialog. @@ -167,8 +166,7 @@ impl cosmic::Application for App { Err(why) => Message::OpenError(Arc::new(why)), } - }) - .map(Into::into); + }); } // Displays an error in the application's warning bar. diff --git a/src/command/mod.rs b/src/command/mod.rs index 24776e43..10e32a28 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -16,18 +16,20 @@ use iced_runtime::command::Action; use std::future::Future; /// Yields a command which contains a batch of commands. -pub fn batch(commands: impl IntoIterator>) -> Command { - Command::batch(commands) +pub fn batch, Y: 'static>( + commands: impl IntoIterator>, +) -> Command { + Command::batch(commands).map(Into::into) } /// Yields a command which will run the future on the runtime executor. -pub fn future(future: impl Future + Send + 'static) -> Command { - Command::single(Action::Future(Box::pin(future))) +pub fn future, Y>(future: impl Future + Send + 'static) -> Command { + Command::single(Action::Future(Box::pin(async move { future.await.into() }))) } /// Yields a command which will return a message. -pub fn message(message: M) -> Command { - future(async move { message }) +pub fn message, Y>(message: X) -> Command { + future(async move { message.into() }) } /// Initiates a window drag.