refactor: Updated to the most recent Rust version with 2024 syntax

This commit is contained in:
2025-11-07 15:50:55 -07:00
parent 667c843fc0
commit 14549afd52
44 changed files with 377 additions and 371 deletions
+13 -13
View File
@@ -2,8 +2,8 @@ use anyhow::Result;
use crossterm::event::{self, Event, KeyCode, KeyModifiers};
use std::{
sync::{
atomic::{AtomicBool, Ordering},
Arc,
atomic::{AtomicBool, Ordering},
},
time::Duration,
};
@@ -69,19 +69,19 @@ pub async fn wait_abort_signal(abort_signal: &AbortSignal) {
}
pub fn poll_abort_signal(abort_signal: &AbortSignal) -> Result<bool> {
if event::poll(Duration::from_millis(25))? {
if let Event::Key(key) = event::read()? {
match key.code {
KeyCode::Char('c') if key.modifiers == KeyModifiers::CONTROL => {
abort_signal.set_ctrlc();
return Ok(true);
}
KeyCode::Char('d') if key.modifiers == KeyModifiers::CONTROL => {
abort_signal.set_ctrld();
return Ok(true);
}
_ => {}
if event::poll(Duration::from_millis(25))?
&& let Event::Key(key) = event::read()?
{
match key.code {
KeyCode::Char('c') if key.modifiers == KeyModifiers::CONTROL => {
abort_signal.set_ctrlc();
return Ok(true);
}
KeyCode::Char('d') if key.modifiers == KeyModifiers::CONTROL => {
abort_signal.set_ctrld();
return Ok(true);
}
_ => {}
}
}
Ok(false)
+1 -1
View File
@@ -3,7 +3,7 @@ use anyhow::Context;
#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
mod internal {
use arboard::Clipboard;
use base64::{engine::general_purpose::STANDARD, Engine as _};
use base64::{Engine as _, engine::general_purpose::STANDARD};
use std::sync::{LazyLock, Mutex};
static CLIPBOARD: LazyLock<Mutex<Option<Clipboard>>> =
+1 -1
View File
@@ -10,7 +10,7 @@ use std::{
process::Command,
};
use anyhow::{anyhow, bail, Context, Result};
use anyhow::{Context, Result, anyhow, bail};
use dirs::home_dir;
use std::sync::LazyLock;
+1 -1
View File
@@ -1,4 +1,4 @@
use base64::{engine::general_purpose::STANDARD, Engine};
use base64::{Engine, engine::general_purpose::STANDARD};
use hmac::{Hmac, Mac};
use sha2::{Digest, Sha256};
+1 -1
View File
@@ -1,6 +1,6 @@
use std::{cell::RefCell, rc::Rc};
use html_to_markdown::{markdown, TagHandler};
use html_to_markdown::{TagHandler, markdown};
pub fn html_to_md(html: &str) -> String {
let mut handlers: Vec<TagHandler> = vec![
+1 -1
View File
@@ -1,7 +1,7 @@
use anyhow::Result;
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyModifiers};
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
use std::io::{stdout, Write};
use std::io::{Write, stdout};
/// Reads a single character from stdin without requiring Enter
/// Returns the character if it's one of the valid options, or the default if Enter is pressed
+1 -1
View File
@@ -1,6 +1,6 @@
use super::*;
use anyhow::{anyhow, Context, Result};
use anyhow::{Context, Result, anyhow};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
+1 -1
View File
@@ -29,7 +29,7 @@ pub use self::variables::*;
use anyhow::{Context, Result};
use fancy_regex::Regex;
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
use fuzzy_matcher::{FuzzyMatcher, skim::SkimMatcherV2};
use is_terminal::IsTerminal;
use std::borrow::Cow;
use std::sync::LazyLock;
+19 -20
View File
@@ -1,7 +1,7 @@
use std::fs;
use std::path::{Component, Path, PathBuf};
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use fancy_regex::Regex;
use indexmap::IndexSet;
use path_absolutize::Absolutize;
@@ -97,11 +97,12 @@ pub fn to_absolute_path(path: &str) -> Result<String> {
pub fn resolve_home_dir(path: &str) -> String {
let mut path = path.to_string();
if path.starts_with("~/") || path.starts_with("~\\") {
if let Some(home_dir) = dirs::home_dir() {
path.replace_range(..1, &home_dir.display().to_string());
}
if (path.starts_with("~/") || path.starts_with("~\\"))
&& let Some(home_dir) = dirs::home_dir()
{
path.replace_range(..1, &home_dir.display().to_string());
}
path
}
@@ -241,22 +242,20 @@ fn add_file(files: &mut IndexSet<String>, suffixes: Option<&Vec<String>>, path:
fn is_valid_extension(suffixes: Option<&Vec<String>>, path: &Path) -> bool {
let filename_regex = Regex::new(r"^.+\.*").unwrap();
if let Some(suffixes) = suffixes {
if !suffixes.is_empty() {
if let Ok(Some(_)) = filename_regex.find(&suffixes.join(",")) {
let file_name = path
.file_name()
.and_then(|v| v.to_str())
.expect("invalid filename")
.to_string();
return suffixes.contains(&file_name);
} else if let Some(extension) =
path.extension().map(|v| v.to_string_lossy().to_string())
{
return suffixes.contains(&extension);
}
return false;
if let Some(suffixes) = suffixes
&& !suffixes.is_empty()
{
if let Ok(Some(_)) = filename_regex.find(&suffixes.join(",")) {
let file_name = path
.file_name()
.and_then(|v| v.to_str())
.expect("invalid filename")
.to_string();
return suffixes.contains(&file_name);
} else if let Some(extension) = path.extension().map(|v| v.to_string_lossy().to_string()) {
return suffixes.contains(&extension);
}
return false;
}
true
}
+2 -2
View File
@@ -1,8 +1,8 @@
use super::*;
use anyhow::{anyhow, bail, Context, Result};
use anyhow::{Context, Result, anyhow, bail};
use fancy_regex::Regex;
use futures_util::{stream, StreamExt};
use futures_util::{StreamExt, stream};
use http::header::CONTENT_TYPE;
use reqwest::Url;
use scraper::{Html, Selector};
+3 -3
View File
@@ -1,10 +1,10 @@
use super::{poll_abort_signal, wait_abort_signal, AbortSignal, IS_STDOUT_TERMINAL};
use super::{AbortSignal, IS_STDOUT_TERMINAL, poll_abort_signal, wait_abort_signal};
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use crossterm::{cursor, queue, style, terminal};
use std::{
future::Future,
io::{stdout, Write},
io::{Write, stdout},
time::Duration,
};
use tokio::{