improv: messages now automatically convert into cosmic::app::Message

This commit is contained in:
Michael Aaron Murphy 2024-05-21 05:12:41 +02:00
parent 752662eedf
commit 0607161276
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
2 changed files with 10 additions and 10 deletions

View file

@ -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.

View file

@ -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<M>(commands: impl IntoIterator<Item = Command<M>>) -> Command<M> {
Command::batch(commands)
pub fn batch<X: 'static + Into<Y>, Y: 'static>(
commands: impl IntoIterator<Item = Command<X>>,
) -> Command<Y> {
Command::batch(commands).map(Into::into)
}
/// Yields a command which will run the future on the runtime executor.
pub fn future<M>(future: impl Future<Output = M> + Send + 'static) -> Command<M> {
Command::single(Action::Future(Box::pin(future)))
pub fn future<X: Into<Y>, Y>(future: impl Future<Output = X> + Send + 'static) -> Command<Y> {
Command::single(Action::Future(Box::pin(async move { future.await.into() })))
}
/// Yields a command which will return a message.
pub fn message<M: Send + 'static>(message: M) -> Command<M> {
future(async move { message })
pub fn message<X: Send + 'static + Into<Y>, Y>(message: X) -> Command<Y> {
future(async move { message.into() })
}
/// Initiates a window drag.