From f8c9cfe8f66359e8842f735ceed607c20179fc99 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Tue, 10 Oct 2023 08:18:21 +0200 Subject: [PATCH] Implement clippy fixes --- src/main.rs | 10 ++++------ src/ui.rs | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 70687ee..0e3ff63 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,10 +22,9 @@ fn main() { let app = Application::builder().application_id(APP_ID).build(); app.connect_activate(move |app| { - let myui = build_ui(&app); - match cli.file.as_ref() { - Some(file) => ui::load_document(file, Rc::clone(&myui)), - None => {} + let myui = build_ui(app); + if let Some(file) = cli.file.as_ref() { + ui::load_document(file, Rc::clone(&myui)); } }); @@ -33,6 +32,5 @@ fn main() { } fn build_ui(app: &Application) -> Rc> { - let ui = Ui::build(app); - ui + Ui::build(app) } diff --git a/src/ui.rs b/src/ui.rs index d440e2a..64f63a8 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, path::PathBuf, rc::Rc}; +use std::{cell::RefCell, path::Path, rc::Rc}; use cairo::{Context, Format, ImageSurface}; use gtk4::{ @@ -190,17 +190,17 @@ fn choose_file(ui: Rc>, window: &ApplicationWindow) { filechooser.connect_response(move |d, response| { if response == ResponseType::Accept { let path = d.file().unwrap().path().unwrap(); - load_document(&path, Rc::clone(&ui)); + load_document(path, Rc::clone(&ui)); } d.destroy(); }); filechooser.show() } -pub fn load_document(file: &PathBuf, ui: Rc>) { +pub fn load_document(file: impl AsRef, ui: Rc>) { println!("Loading file..."); // TODO: catch errors, maybe show error dialog - let uri = format!("file://{}", file.to_str().unwrap()); + let uri = format!("file://{}", file.as_ref().to_str().unwrap()); let document_canvas = DocumentCanvas::new(poppler::Document::from_file(&uri, None).unwrap()); ui.borrow_mut().document_canvas = Some(document_canvas);