diff --git a/models/src/lib.rs b/models/src/lib.rs index 5a4b2ec..5fc752f 100644 --- a/models/src/lib.rs +++ b/models/src/lib.rs @@ -14,7 +14,7 @@ impl Display for TxtRecord { if self.val.is_none() { write!(f, "{}", self.key) } else { - write!(f, "{}={}", self.key, self.val.clone().unwrap()) + write!(f, "{}={}", self.key, self.val.clone().expect("To exist")) } } } @@ -40,7 +40,9 @@ impl ResolvedService { pub fn timestamp_millis() -> u64 { let now = SystemTime::now(); - let since_epoch = now.duration_since(SystemTime::UNIX_EPOCH).unwrap(); + let since_epoch = now + .duration_since(SystemTime::UNIX_EPOCH) + .expect("To have a duration since unix epoch"); since_epoch.as_secs() * 1000 + u64::from(since_epoch.subsec_millis()) } @@ -189,7 +191,7 @@ pub fn check_service_type_fully_qualified(service_type: &str) -> Result<(), Mdns } // Remove the trailing dot for validation purposes - let service_type = service_type.strip_suffix('.').unwrap(); + let service_type = service_type.strip_suffix('.').expect("To end with ."); // Split into parts based on dots let parts: Vec<&str> = service_type.split('.').collect(); @@ -201,7 +203,7 @@ pub fn check_service_type_fully_qualified(service_type: &str) -> Result<(), Mdns return Err(MdnsError::IncorrectFormat); } - let domain = parts.last().unwrap(); // Domain is always the last component + let domain = parts.last().expect("To have a domain"); // Domain is always the last component let protocol = parts[parts.len() - 2]; // Protocol is the second-to-last component // Validate protocol name (must be either _tcp or _udp) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index fd337ed..ee1f2e9 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -113,7 +113,7 @@ fn from_service_info(info: &ServiceInfo) -> ResolvedService { val: bytes_option_to_string_option_with_escaping(r.val()), }) .collect(); - sorted_txt.sort_by(|a, b| a.key.partial_cmp(&b.key).unwrap()); + sorted_txt.sort_by(|a, b| a.key.partial_cmp(&b.key).expect("To be partial comparable")); ResolvedService { instance_name: info.get_fullname().into(), hostname: info.get_hostname().into(), @@ -347,8 +347,7 @@ fn copy_to_clipboard(window: Window, contents: String) { let app = window.app_handle(); app.clipboard() .write_text(contents) - .map_err(|err| log::error!("Failed to write to clipboard: {}", err)) - .unwrap(); + .expect("To write to clipboard"); } #[cfg(desktop)] @@ -395,7 +394,7 @@ mod app_updates { current_version: update.current_version.clone(), }); - *pending_update.0.lock().unwrap() = update; + *pending_update.0.lock().expect("To lock") = update; Ok(update_metadata) } @@ -405,7 +404,7 @@ mod app_updates { app: AppHandle, pending_update: State<'_, PendingUpdate>, ) -> Result<()> { - let Some(update) = pending_update.0.lock().unwrap().take() else { + let Some(update) = pending_update.0.lock().expect("To lock").take() else { return Err(Error::NoPendingUpdate); }; @@ -450,13 +449,17 @@ pub fn run() { ) .plugin(tauri_plugin_updater::Builder::new().build()) .setup(|app| { - let splashscreen_window = app.get_webview_window("splashscreen").unwrap(); - let main_window = app.get_webview_window("main").unwrap(); + let splashscreen_window = app + .get_webview_window("splashscreen") + .expect("Splashscreen window to exist"); + let main_window = app + .get_webview_window("main") + .expect("Main window to exist"); tauri::async_runtime::spawn(async move { #[cfg(not(debug_assertions))] tokio::time::sleep(SPLASH_SCREEN_DURATION).await; - splashscreen_window.close().unwrap(); - main_window.show().unwrap(); + splashscreen_window.close().expect("To close"); + main_window.show().expect("To show"); #[cfg(debug_assertions)] main_window.open_devtools(); }); diff --git a/src/app.rs b/src/app.rs index 279ca31..562c22a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -345,8 +345,8 @@ fn ResolvedServiceGridItem(resolved_service: ResolvedService) -> impl IntoView { log::debug!("ResolvedServiceGridItem"); let mut hostname = resolved_service.hostname; hostname.pop(); // remove the trailing dot - let updated_at = - DateTime::from_timestamp_millis(resolved_service.updated_at_ms as i64).unwrap(); + let updated_at = DateTime::from_timestamp_millis(resolved_service.updated_at_ms as i64) + .expect("To get convert"); let as_local_datetime: DateTime = updated_at.with_timezone(&Local); let addrs = resolved_service .addresses @@ -416,8 +416,9 @@ fn Browse() -> impl IntoView { log::debug!("Browse"); let (resolved, set_resolved) = create_signal(ResolvedServices::new()); create_resource(move || set_resolved, listen_on_resolve_events); - - let is_desktop = use_context::().unwrap().0; + let is_desktop = use_context::() + .expect("is_desktop context to exist") + .0; let browsing = create_rw_signal(false); let service_type = create_rw_signal(String::new()); let not_browsing = Signal::derive(move || !browsing.get());