Skip to content

Commit

Permalink
review unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
galister committed Aug 3, 2024
1 parent aca1776 commit c29bbbb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/backend/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
15 changes: 10 additions & 5 deletions src/backend/openxr/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 {
Expand All @@ -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
);
}
}
}
Expand Down Expand Up @@ -420,7 +425,7 @@ fn to_path(maybe_path_str: &Option<String>, instance: &xr::Instance) -> Option<x
fn is_bool(maybe_type_str: &Option<String>) -> bool {
maybe_type_str
.as_ref()
.unwrap()
.unwrap() // want panic
.split('/')
.last()
.map(|last| matches!(last, "click" | "touch"))
Expand Down
13 changes: 10 additions & 3 deletions src/backend/openxr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ pub fn openxr_run(running: Arc<AtomicBool>, 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() {
Expand Down Expand Up @@ -432,12 +436,15 @@ pub fn openxr_run(running: Arc<AtomicBool>, 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 => {
Expand Down
5 changes: 3 additions & 2 deletions src/backend/uidev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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::<Vec<_>>();

Expand Down
6 changes: 3 additions & 3 deletions src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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())?;

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/gui/modular/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
Expand Down
16 changes: 9 additions & 7 deletions src/overlays/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<KeyboardData, KeyButtonData>,
Expand Down

0 comments on commit c29bbbb

Please sign in to comment.