From 7c1305438396da0764ad55be51f5611c2302f2fb Mon Sep 17 00:00:00 2001 From: itsjunetime Date: Sat, 26 Oct 2024 15:45:20 -0600 Subject: [PATCH] Fix a few more small clippy issues --- Cargo.toml | 1 - benches/utils.rs | 4 ++-- src/main.rs | 13 ++++++------- src/renderer.rs | 8 ++++---- src/tui.rs | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0ff862a..bb01bee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ readme = "README.md" homepage = "https://github.com/itsjunetime/tdf" repository = "https://github.com/itsjunetime/tdf" license = "MPL-2.0" -license-file = "LICENSE" keywords = ["pdf", "tui", "cli", "terminal"] categories = ["command-line-utilities", "text-processing", "visualization"] default-run = "tdf" diff --git a/benches/utils.rs b/benches/utils.rs index b14e27f..4cf4583 100644 --- a/benches/utils.rs +++ b/benches/utils.rs @@ -75,7 +75,7 @@ pub fn start_rendering_loop( width: columns * FONT_SIZE.0 }; - std::thread::spawn(move || start_rendering(str_path, to_main_tx, from_main_rx, size)); + std::thread::spawn(move || start_rendering(&str_path, to_main_tx, from_main_rx, size)); let main_area = Rect { x: 0, @@ -136,7 +136,7 @@ pub async fn render_doc(path: impl AsRef) { to_render_tx } = start_all_rendering(path); - while pages.is_empty() || pages.iter().any(|p| p.is_none()) { + while pages.is_empty() || pages.iter().any(Option::is_none) { tokio::select! { Some(renderer_msg) = from_render_rx.next() => { handle_renderer_msg(renderer_msg, &mut pages, &mut to_converter_tx); diff --git a/src/main.rs b/src/main.rs index 22c3fc1..9a89402 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ async fn main() -> Result<(), Box> { // read in the returned size until we hit a 't' (which indicates to us it's done) let input_vec = std::io::stdin() .bytes() - .flat_map(|b| b.ok()) + .filter_map(Result::ok) .take_while(|b| *b != b't') .collect::>(); @@ -144,7 +144,7 @@ async fn main() -> Result<(), Box> { // We need to use the thread::spawn API so that this exists in a thread not owned by tokio, // since the methods we call in `start_rendering` will panic if called in an async context std::thread::spawn(move || { - renderer::start_rendering(file_path, render_tx, render_rx, window_size) + renderer::start_rendering(&file_path, render_tx, render_rx, window_size) }); let mut ev_stream = crossterm::event::EventStream::new(); @@ -154,11 +154,10 @@ async fn main() -> Result<(), Box> { tokio::spawn(run_conversion_loop(to_main, from_main, picker, 20)); - let file_name = path - .file_name() - .map(|n| n.to_string_lossy()) - .unwrap_or_else(|| "Unknown file".into()) - .to_string(); + let file_name = path.file_name().map_or_else( + || "Unknown file".into(), + |n| n.to_string_lossy().to_string() + ); let mut tui = tui::Tui::new(file_name); let backend = CrosstermBackend::new(std::io::stdout()); diff --git a/src/renderer.rs b/src/renderer.rs index 456354e..768d7d8 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -65,7 +65,7 @@ pub fn fill_default(vec: &mut Vec, size: usize) { // means the other side's disconnected, which means that the main thread has panicked, which means // we're done. pub fn start_rendering( - path: String, + path: &str, mut sender: Sender>, receiver: Receiver, size: WindowSize @@ -90,7 +90,7 @@ pub fn start_rendering( let col_h = size.height / size.rows; 'reload: loop { - let doc = match Document::from_file(&path, None) { + let doc = match Document::from_file(path, None) { Err(e) => { // if there's an error, tell the main loop sender.send(Err(RenderError::Doc(e)))?; @@ -189,8 +189,8 @@ pub fn start_rendering( .map(|(idx, p)| (start_point - (idx + 1), p)) ); - let area_w = area.width as f64 * col_w as f64; - let area_h = area.height as f64 * col_h as f64; + let area_w = f64::from(area.width) * f64::from(col_w); + let area_h = f64::from(area.height) * f64::from(col_h); // we go through each page for (num, rendered) in page_iter { diff --git a/src/tui.rs b/src/tui.rs index b14a4e8..0ba3a09 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -204,7 +204,7 @@ impl Tui { // and only take as many as are ready to be rendered .take_while(|(_, page)| page.img.is_some()) // and map it to their width (in cells on the terminal, not pixels) - .flat_map(|(idx, page)| page.img.as_ref().map(|img| (idx, img.rect().width))) + .filter_map(|(idx, page)| page.img.as_ref().map(|img| (idx, img.rect().width))) // and then take them as long as they won't overflow the available area. .take_while(|(_, width)| match test_area_w.checked_sub(*width) { Some(new_val) => {