From f3108251942a3b9e6985939ff43fe8c30eb8f3ff Mon Sep 17 00:00:00 2001 From: drendog Date: Wed, 21 Aug 2024 01:02:58 +0200 Subject: [PATCH] refactor: remove unnecessary unwraps --- Cargo.toml | 1 + src/windowing/mod.rs | 9 +++++++-- src/windowing/state/builder.rs | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b20ebf..fee9e30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ pedantic = { level = "warn", priority = -1 } clone_on_ref_ptr = "warn" multiple-crate-versions = "allow" module_name_repetitions = "allow" +unwrap_used = "warn" [dependencies] anyhow = "1.0.86" diff --git a/src/windowing/mod.rs b/src/windowing/mod.rs index c22c234..37d0c38 100644 --- a/src/windowing/mod.rs +++ b/src/windowing/mod.rs @@ -56,7 +56,12 @@ impl WindowingSystem { let pointer = Rc::new(seat.get_pointer(&event_queue.handle(), ())); let mut state_builder = WindowStateBuilder::new() - .component_definition(config.component_definition.take().unwrap()) + .component_definition( + config + .component_definition + .take() + .context("Component definition is required")?, + ) .surface(Rc::clone(&surface)) .layer_surface(Rc::clone(&layer_surface)) .pointer(Rc::clone(&pointer)) @@ -218,7 +223,7 @@ impl WindowingSystem { .read() .map_err(|e| anyhow::anyhow!("Failed to read events: {}", e))?; } - connection.flush().unwrap(); + connection.flush()?; event_queue.dispatch_pending(shared_data)?; diff --git a/src/windowing/state/builder.rs b/src/windowing/state/builder.rs index a8b2505..70bd6b9 100644 --- a/src/windowing/state/builder.rs +++ b/src/windowing/state/builder.rs @@ -4,7 +4,7 @@ use slint_interpreter::ComponentDefinition; use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1; use wayland_client::protocol::{wl_pointer::WlPointer, wl_surface::WlSurface}; use crate::rendering::{femtovg_window::FemtoVGWindow, slint_platform::CustomSlintPlatform}; -use anyhow::Result; +use anyhow::{Context, Result}; use super::WindowState; @@ -77,7 +77,9 @@ impl WindowStateBuilder { } pub fn build(self) -> Result { - let platform = CustomSlintPlatform::new(Rc::clone(self.window.as_ref().unwrap())); + let platform = CustomSlintPlatform::new(Rc::clone( + self.window.as_ref().context("Window is required")?, + )); slint::platform::set_platform(Box::new(platform)) .map_err(|e| anyhow::anyhow!("Failed to set platform: {:?}", e))?;