From c29bbbb1421bebd55c1c8ab528c303415b868545 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 3 Aug 2024 20:50:34 +0900 Subject: [PATCH] review unwraps --- src/backend/input.rs | 2 +- src/backend/openxr/input.rs | 15 ++++++++++----- src/backend/openxr/mod.rs | 13 ++++++++++--- src/backend/uidev/mod.rs | 5 +++-- src/graphics/mod.rs | 6 +++--- src/gui/modular/label.rs | 1 + src/overlays/keyboard.rs | 16 +++++++++------- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/backend/input.rs b/src/backend/input.rs index 9ca6a7b..1b39511 100644 --- a/src/backend/input.rs +++ b/src/backend/input.rs @@ -547,7 +547,7 @@ impl Pointer { } config.transform_values.arc_set( overlay.state.name.clone(), - overlay.state.saved_transform.unwrap(), + overlay.state.saved_transform.unwrap(), // safe ); } diff --git a/src/backend/openxr/input.rs b/src/backend/openxr/input.rs index 75935fa..e50b262 100644 --- a/src/backend/openxr/input.rs +++ b/src/backend/openxr/input.rs @@ -5,9 +5,9 @@ use std::{ }; use glam::{bool, Affine3A, Quat, Vec3}; +use libmonado_rs::{Device, Monado}; use openxr::{self as xr, Quaternionf, Vector3f}; use serde::{Deserialize, Serialize}; -use libmonado_rs::{Monado, Device}; use crate::{ backend::input::{Haptics, Pointer, TrackedDevice, TrackedDeviceRole}, @@ -213,7 +213,7 @@ impl OpenXrInputSource { fn update_device_battery_status( device: &mut Device, role: TrackedDeviceRole, - app: &mut AppState + app: &mut AppState, ) { if let Ok(status) = device.battery_status() { if status.present { @@ -222,8 +222,13 @@ impl OpenXrInputSource { charging: status.charging, role, }); - log::debug!("Device {} role {:#?}: {:.0}% (charging {})", device.index, role, - status.charge * 100.0f32, status.charging); + log::debug!( + "Device {} role {:#?}: {:.0}% (charging {})", + device.index, + role, + status.charge * 100.0f32, + status.charging + ); } } } @@ -420,7 +425,7 @@ fn to_path(maybe_path_str: &Option, instance: &xr::Instance) -> Option) -> bool { maybe_type_str .as_ref() - .unwrap() + .unwrap() // want panic .split('/') .last() .map(|last| matches!(last, "click" | "touch")) diff --git a/src/backend/openxr/mod.rs b/src/backend/openxr/mod.rs index 6d1540f..3132ef3 100644 --- a/src/backend/openxr/mod.rs +++ b/src/backend/openxr/mod.rs @@ -252,7 +252,11 @@ pub fn openxr_run(running: Arc, show_by_default: bool) -> Result<(), watch_fade(&mut app_state, overlays.mut_by_id(watch_id).unwrap()); // want panic if let Some(ref mut space_mover) = playspace { - space_mover.update(&mut overlays, &app_state, monado.as_mut().unwrap()); + space_mover.update( + &mut overlays, + &app_state, + monado.as_mut().unwrap(), // safe + ); } for o in overlays.iter_mut() { @@ -432,12 +436,15 @@ pub fn openxr_run(running: Arc, show_by_default: bool) -> Result<(), TaskType::System(task) => match task { SystemTask::FixFloor => { if let Some(ref mut playspace) = playspace { - playspace.fix_floor(&app_state.input_state, monado.as_mut().unwrap()); + playspace.fix_floor( + &app_state.input_state, + monado.as_mut().unwrap(), // safe + ); } } SystemTask::ResetPlayspace => { if let Some(ref mut playspace) = playspace { - playspace.reset_offset(monado.as_mut().unwrap()); + playspace.reset_offset(monado.as_mut().unwrap()); // safe } } SystemTask::ShowHide => { diff --git a/src/backend/uidev/mod.rs b/src/backend/uidev/mod.rs index 2583f9a..d4eda35 100644 --- a/src/backend/uidev/mod.rs +++ b/src/backend/uidev/mod.rs @@ -237,7 +237,7 @@ fn create_swapchain( .device .physical_device() .surface_capabilities(&surface, Default::default()) - .unwrap(); + .unwrap(); // want panic let (swapchain, images) = Swapchain::new( graphics.device.clone(), @@ -251,13 +251,14 @@ fn create_swapchain( .supported_composite_alpha .into_iter() .next() - .unwrap(), + .unwrap(), // want panic ..Default::default() }, )?; let image_views = images .into_iter() + // want panic .map(|image| ImageView::new_default(image).unwrap()) .collect::>(); diff --git a/src/graphics/mod.rs b/src/graphics/mod.rs index 5a713c8..dd3a258 100644 --- a/src/graphics/mod.rs +++ b/src/graphics/mod.rs @@ -554,7 +554,7 @@ impl WlxGraphics { use vulkano::swapchain::Surface; use winit::{event_loop::EventLoop, window::Window}; - let event_loop = EventLoop::new().unwrap(); + let event_loop = EventLoop::new().unwrap(); // want panic let mut vk_instance_extensions = Surface::required_extensions(&event_loop).unwrap(); vk_instance_extensions.khr_get_physical_device_properties2 = true; log::debug!("Instance exts for runtime: {:?}", &vk_instance_extensions); @@ -571,7 +571,7 @@ impl WlxGraphics { let window = Arc::new( event_loop .create_window(Window::default_attributes()) - .unwrap(), + .unwrap(), // want panic ); let surface = Surface::from_window(instance.clone(), window.clone())?; @@ -640,7 +640,7 @@ impl WlxGraphics { let native_format = device .physical_device() .surface_formats(&surface, Default::default()) - .unwrap()[0] + .unwrap()[0] // want panic .0; log::info!("Using surface format: {:?}", native_format); diff --git a/src/gui/modular/label.rs b/src/gui/modular/label.rs index b1a2f67..d3bf862 100644 --- a/src/gui/modular/label.rs +++ b/src/gui/modular/label.rs @@ -123,6 +123,7 @@ pub fn modular_label_init(label: &mut ModularControl, content: &LabelContent) { } pub(super) fn label_update(control: &mut ModularControl, _: &mut (), app: &mut AppState) { + // want panic let ModularData::Label(data) = control.state.as_mut().unwrap() else { panic!("Label control has no state"); }; diff --git a/src/overlays/keyboard.rs b/src/overlays/keyboard.rs index 1c86989..9678c92 100644 --- a/src/overlays/keyboard.rs +++ b/src/overlays/keyboard.rs @@ -133,12 +133,14 @@ where continue; } let mut iter = exec_args.iter().cloned(); - maybe_state = Some(KeyButtonData::Exec { - program: iter.next().unwrap(), - args: iter.by_ref().take_while(|arg| arg[..] != *"null").collect(), - release_program: iter.next(), - release_args: iter.collect(), - }); + if let Some(program) = iter.next() { + maybe_state = Some(KeyButtonData::Exec { + program, + args: iter.by_ref().take_while(|arg| arg[..] != *"null").collect(), + release_program: iter.next(), + release_args: iter.collect(), + }) + }; } else { log::error!("Unknown key: {}", key); } @@ -269,7 +271,7 @@ fn key_release( } } -static PRESS_COLOR: Vec4 = Vec4::new(198./255., 160./255., 246./255., 0.5); +static PRESS_COLOR: Vec4 = Vec4::new(198. / 255., 160. / 255., 246. / 255., 0.5); fn test_highlight( control: &Control,