summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-09-08 00:35:17 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-09-08 00:44:59 +0200
commitc1f79b40cf704cafc807250b177fc7d3444fe54f (patch)
tree31c0cf2b8d166976dc819f020e0185f9d8c2bdcd /winit
parentfaa12382d4d7a44ab60fa5bf2a5024a34dbb2e8d (diff)
downloadiced-c1f79b40cf704cafc807250b177fc7d3444fe54f.tar.gz
iced-c1f79b40cf704cafc807250b177fc7d3444fe54f.tar.bz2
iced-c1f79b40cf704cafc807250b177fc7d3444fe54f.zip
Make `Application` and `Sandbox` return a `Result`
Diffstat (limited to 'winit')
-rw-r--r--winit/Cargo.toml5
-rw-r--r--winit/src/application.rs15
-rw-r--r--winit/src/error.rs27
-rw-r--r--winit/src/lib.rs2
4 files changed, 43 insertions, 6 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index 7fe83b96..06e5df9a 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -17,6 +17,7 @@ debug = ["iced_native/debug"]
winit = "0.22"
window_clipboard = "0.1"
log = "0.4"
+thiserror = "1.0"
[dependencies.iced_native]
version = "0.2"
@@ -26,5 +27,9 @@ path = "../native"
version = "0.1"
path = "../graphics"
+[dependencies.iced_futures]
+version = "0.1"
+path = "../futures"
+
[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.6"
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 73dad398..12f92053 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -1,7 +1,9 @@
//! Create interactive, native cross-platform applications.
+use crate::conversion;
+use crate::mouse;
use crate::{
- conversion, mouse, Clipboard, Color, Command, Debug, Executor, Mode, Proxy,
- Runtime, Settings, Size, Subscription,
+ Clipboard, Color, Command, Debug, Error, Executor, Mode, Proxy, Runtime,
+ Settings, Size, Subscription,
};
use iced_graphics::window;
use iced_graphics::Viewport;
@@ -108,7 +110,8 @@ pub trait Application: Program {
pub fn run<A, E, C>(
settings: Settings<A::Flags>,
compositor_settings: C::Settings,
-) where
+) -> Result<(), Error>
+where
A: Application + 'static,
E: Executor + 'static,
C: window::Compositor<Renderer = A::Renderer> + 'static,
@@ -123,7 +126,7 @@ pub fn run<A, E, C>(
let event_loop = EventLoop::with_user_event();
let mut runtime = {
- let executor = E::new().expect("Create executor");
+ let executor = E::new().map_err(Error::ExecutorCreationFailed)?;
let proxy = Proxy::new(event_loop.create_proxy());
Runtime::new(executor, proxy)
@@ -145,7 +148,7 @@ pub fn run<A, E, C>(
.window
.into_builder(&title, mode, event_loop.primary_monitor())
.build(&event_loop)
- .expect("Open window");
+ .map_err(Error::WindowCreationFailed)?;
let clipboard = Clipboard::new(&window);
// TODO: Encode cursor availability in the type-system
@@ -160,7 +163,7 @@ pub fn run<A, E, C>(
);
let mut resized = false;
- let (mut compositor, mut renderer) = C::new(compositor_settings);
+ let (mut compositor, mut renderer) = C::new(compositor_settings)?;
let surface = compositor.create_surface(&window);
diff --git a/winit/src/error.rs b/winit/src/error.rs
new file mode 100644
index 00000000..8e1d20e8
--- /dev/null
+++ b/winit/src/error.rs
@@ -0,0 +1,27 @@
+use iced_futures::futures;
+
+/// An error that occurred while running an application.
+#[derive(Debug, thiserror::Error)]
+pub enum Error {
+ /// The futures executor could not be created.
+ #[error("the futures executor could not be created")]
+ ExecutorCreationFailed(futures::io::Error),
+
+ /// The application window could not be created.
+ #[error("the application window could not be created")]
+ WindowCreationFailed(winit::error::OsError),
+
+ /// A suitable graphics adapter or device could not be found.
+ #[error("a suitable graphics adapter or device could not be found")]
+ GraphicsAdapterNotFound,
+}
+
+impl From<iced_graphics::Error> for Error {
+ fn from(error: iced_graphics::Error) -> Error {
+ match error {
+ iced_graphics::Error::AdapterNotFound => {
+ Error::GraphicsAdapterNotFound
+ }
+ }
+ }
+}
diff --git a/winit/src/lib.rs b/winit/src/lib.rs
index bdab3ed7..8ca8eec1 100644
--- a/winit/src/lib.rs
+++ b/winit/src/lib.rs
@@ -30,11 +30,13 @@ pub mod conversion;
pub mod settings;
mod clipboard;
+mod error;
mod mode;
mod proxy;
pub use application::Application;
pub use clipboard::Clipboard;
+pub use error::Error;
pub use mode::Mode;
pub use proxy::Proxy;
pub use settings::Settings;