summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2025-06-28 19:17:43 +0800
committerGitHub <noreply@github.com>2025-06-28 19:17:43 +0800
commit419790fb74fbaf47d54519238b5a542a3875961e (patch)
tree8917db58a4a77a514079bf115d670a3f82003c03 /src/utils
parentbad300bbce72dff6f085fc8b94e8ffbdd103f47f (diff)
downloadaichat-419790fb74fbaf47d54519238b5a542a3875961e.tar.gz
chore: clippy (#1334)
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/clipboard.rs4
-rw-r--r--src/utils/command.rs2
-rw-r--r--src/utils/crypto.rs2
-rw-r--r--src/utils/mod.rs2
-rw-r--r--src/utils/request.rs12
-rw-r--r--src/utils/variables.rs2
6 files changed, 9 insertions, 15 deletions
diff --git a/src/utils/clipboard.rs b/src/utils/clipboard.rs
index cb92bce..6b87ff7 100644
--- a/src/utils/clipboard.rs
+++ b/src/utils/clipboard.rs
@@ -8,7 +8,7 @@ static CLIPBOARD: std::sync::LazyLock<std::sync::Mutex<Option<arboard::Clipboard
/// Works in many modern terminals, including over SSH.
fn set_text_osc52(text: &str) -> anyhow::Result<()> {
let encoded = BASE64.encode(text);
- let seq = format!("\x1b]52;c;{}\x07", encoded);
+ let seq = format!("\x1b]52;c;{encoded}\x07");
// Write to stdout:
if let Err(e) = std::io::Write::write_all(&mut std::io::stdout(), seq.as_bytes()) {
return Err(anyhow::anyhow!("Failed to send OSC52 sequence").context(e));
@@ -35,7 +35,7 @@ pub fn set_text(text: &str) -> anyhow::Result<()> {
match set_text_osc52(text) {
Ok(()) => Ok(()),
Err(osc_err) => Err(anyhow::anyhow!("No clipboard available")
- .context(format!("Failed to copy (OSC52 error: {})", osc_err))),
+ .context(format!("Failed to copy (OSC52 error: {osc_err})"))),
}
}
diff --git a/src/utils/command.rs b/src/utils/command.rs
index 14a40a4..7d98504 100644
--- a/src/utils/command.rs
+++ b/src/utils/command.rs
@@ -175,7 +175,7 @@ pub fn append_to_shell_history(shell: &str, command: &str, exit_code: i32) -> io
.create(true)
.append(true)
.open(&history_file)?;
- writeln!(file, "{}", history_txt)?;
+ writeln!(file, "{history_txt}")?;
}
Ok(())
}
diff --git a/src/utils/crypto.rs b/src/utils/crypto.rs
index 9f0ee82..494ea84 100644
--- a/src/utils/crypto.rs
+++ b/src/utils/crypto.rs
@@ -17,7 +17,7 @@ pub fn hmac_sha256(key: &[u8], msg: &str) -> Vec<u8> {
pub fn hex_encode(bytes: &[u8]) -> String {
bytes
.iter()
- .fold(String::new(), |acc, b| acc + &format!("{:02x}", b))
+ .fold(String::new(), |acc, b| acc + &format!("{b:02x}"))
}
pub fn encode_uri(uri: &str) -> String {
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 98f2da1..6c5b08a 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -162,7 +162,7 @@ pub fn indent_text<T: ToString>(s: T, size: usize) -> String {
let indent_str = " ".repeat(size);
s.to_string()
.split('\n')
- .map(|line| format!("{}{}", indent_str, line))
+ .map(|line| format!("{indent_str}{line}"))
.collect::<Vec<String>>()
.join("\n")
}
diff --git a/src/utils/request.rs b/src/utils/request.rs
index 8cee0a0..95c4f9c 100644
--- a/src/utils/request.rs
+++ b/src/utils/request.rs
@@ -131,7 +131,7 @@ pub async fn fetch_with_loaders(
}
let image_bytes = res.bytes().await?;
let image_base64 = base64_encode(&image_bytes);
- let contents = format!("data:{};base64,{}", content_type, image_base64);
+ let contents = format!("data:{content_type};base64,{image_base64}");
(contents, extension)
} else {
match loaders.get(&extension) {
@@ -316,10 +316,7 @@ async fn crawl_gh_tree(start_url: &Url, exclude: &[String]) -> Result<Vec<String
let branch = path_segs[4];
let root_path = path_segs[5..].join("/");
- let url = format!(
- "https://api.github.com/repos/{}/{}/git/ref/heads/{}",
- owner, repo, branch
- );
+ let url = format!("https://api.github.com/repos/{owner}/{repo}/git/ref/heads/{branch}");
let res_body: Value = client
.get(&url)
@@ -335,10 +332,7 @@ async fn crawl_gh_tree(start_url: &Url, exclude: &[String]) -> Result<Vec<String
.as_str()
.ok_or_else(|| anyhow!("Not found branch or tag"))?;
- let url = format!(
- "https://api.github.com/repos/{}/{}/git/trees/{}?recursive=true",
- owner, repo, sha
- );
+ let url = format!("https://api.github.com/repos/{owner}/{repo}/git/trees/{sha}?recursive=true");
let res_body: Value = client
.get(&url)
diff --git a/src/utils/variables.rs b/src/utils/variables.rs
index bfec4ca..991da2a 100644
--- a/src/utils/variables.rs
+++ b/src/utils/variables.rs
@@ -25,7 +25,7 @@ pub fn interpolate_variables(text: &mut String) {
"__cwd__" => env::current_dir()
.map(|v| v.display().to_string())
.unwrap_or_default(),
- _ => format!("{{{{{}}}}}", key),
+ _ => format!("{{{{{key}}}}}"),
}
})
.to_string();