diff options
author | 2020-09-08 00:35:17 +0200 | |
---|---|---|
committer | 2020-09-08 00:44:59 +0200 | |
commit | c1f79b40cf704cafc807250b177fc7d3444fe54f (patch) | |
tree | 31c0cf2b8d166976dc819f020e0185f9d8c2bdcd /glutin/src | |
parent | faa12382d4d7a44ab60fa5bf2a5024a34dbb2e8d (diff) | |
download | iced-c1f79b40cf704cafc807250b177fc7d3444fe54f.tar.gz iced-c1f79b40cf704cafc807250b177fc7d3444fe54f.tar.bz2 iced-c1f79b40cf704cafc807250b177fc7d3444fe54f.zip |
Make `Application` and `Sandbox` return a `Result`
Diffstat (limited to 'glutin/src')
-rw-r--r-- | glutin/src/application.rs | 20 | ||||
-rw-r--r-- | glutin/src/lib.rs | 2 |
2 files changed, 16 insertions, 6 deletions
diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 3be9b65f..fe6ad99d 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -1,5 +1,5 @@ //! Create interactive, native cross-platform applications. -use crate::{mouse, Executor, Runtime, Size}; +use crate::{mouse, Error, Executor, Runtime, Size}; use iced_graphics::window; use iced_graphics::Viewport; use iced_winit::application; @@ -16,7 +16,8 @@ pub use iced_winit::{program, 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::GLCompositor<Renderer = A::Renderer> + 'static, @@ -32,7 +33,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) @@ -61,7 +62,16 @@ pub fn run<A, E, C>( .with_vsync(true) .with_multisampling(C::sample_count(&compositor_settings) as u16) .build_windowed(builder, &event_loop) - .expect("Open window"); + .map_err(|error| { + use glutin::CreationError; + + match error { + CreationError::Window(error) => { + Error::WindowCreationFailed(error) + } + _ => Error::GraphicsAdapterNotFound, + } + })?; #[allow(unsafe_code)] unsafe { @@ -85,7 +95,7 @@ pub fn run<A, E, C>( let (mut compositor, mut renderer) = unsafe { C::new(compositor_settings, |address| { context.get_proc_address(address) - }) + })? }; let mut state = program::State::new( diff --git a/glutin/src/lib.rs b/glutin/src/lib.rs index b0e0bdd4..49bc2a33 100644 --- a/glutin/src/lib.rs +++ b/glutin/src/lib.rs @@ -15,7 +15,7 @@ pub use iced_native::*; pub mod application; pub use iced_winit::settings; -pub use iced_winit::Mode; +pub use iced_winit::{Error, Mode}; #[doc(no_inline)] pub use application::Application; |