fix: resolve clippy warnings (matches!, map_or, redundant guard, unnecessary allocations)

This commit is contained in:
Nikketryhard
2026-02-14 04:06:18 -06:00
parent 725bdb4e9a
commit 901cd3d2e3
7 changed files with 14 additions and 32 deletions

View File

@@ -233,7 +233,7 @@ async fn chat_completions_stream(
"finish_reason": "stop", "finish_reason": "stop",
}], }],
})).unwrap_or_default())); })).unwrap_or_default()));
yield Ok(Event::default().data("[DONE]".to_string())); yield Ok(Event::default().data("[DONE]"));
return; return;
} }
@@ -257,7 +257,7 @@ async fn chat_completions_stream(
"finish_reason": "stop", "finish_reason": "stop",
}], }],
})).unwrap_or_default())); })).unwrap_or_default()));
yield Ok(Event::default().data("[DONE]".to_string())); yield Ok(Event::default().data("[DONE]"));
return; return;
} }
} }
@@ -284,7 +284,7 @@ async fn chat_completions_stream(
"finish_reason": "stop", "finish_reason": "stop",
}], }],
})).unwrap_or_default())); })).unwrap_or_default()));
yield Ok(Event::default().data("[DONE]".to_string())); yield Ok(Event::default().data("[DONE]"));
}; };
Sse::new(stream) Sse::new(stream)

View File

@@ -237,14 +237,14 @@ pub(crate) async fn poll_for_response(
info!( info!(
"Response done ({short_id}), {:.1}s, {} chars, tokens: {}in/{}out ({}){}{}", "Response done ({short_id}), {:.1}s, {} chars, tokens: {}in/{}out ({}){}{}",
elapsed, text.len(), u.input_tokens, u.output_tokens, u.model, elapsed, text.len(), u.input_tokens, u.output_tokens, u.model,
if thinking.is_some() { format!(", thinking: {} chars", thinking.as_ref().unwrap().len()) } else { String::new() }, thinking.as_ref().map_or(String::new(), |t| format!(", thinking: {} chars", t.len())),
if thinking_signature.is_some() { ", has sig" } else { "" } if thinking_signature.is_some() { ", has sig" } else { "" }
); );
} else { } else {
info!( info!(
"Response done ({short_id}), {:.1}s, {} chars (no usage){}{}", "Response done ({short_id}), {:.1}s, {} chars (no usage){}{}",
elapsed, text.len(), elapsed, text.len(),
if thinking.is_some() { format!(", thinking: {} chars", thinking.as_ref().unwrap().len()) } else { String::new() }, thinking.as_ref().map_or(String::new(), |t| format!(", thinking: {} chars", t.len())),
if thinking_signature.is_some() { ", has sig" } else { "" } if thinking_signature.is_some() { ", has sig" } else { "" }
); );
} }

View File

@@ -206,7 +206,7 @@ pub(crate) async fn handle_responses(
.send_message(&cascade_id, &user_text, model.model_enum) .send_message(&cascade_id, &user_text, model.model_enum)
.await .await
{ {
Ok((status, _)) if status == 200 => { Ok((200, _)) => {
let bg = Arc::clone(&state.backend); let bg = Arc::clone(&state.backend);
let cid = cascade_id.clone(); let cid = cascade_id.clone();
tokio::spawn(async move { tokio::spawn(async move {

View File

@@ -141,6 +141,7 @@ pub(crate) struct OutputTokensDetails {
} }
#[derive(Serialize, Clone)] #[derive(Serialize, Clone)]
#[derive(Default)]
pub(crate) struct Reasoning { pub(crate) struct Reasoning {
pub effort: Option<String>, pub effort: Option<String>,
pub summary: Option<String>, pub summary: Option<String>,
@@ -161,8 +162,8 @@ impl Usage {
/// Estimate token counts from actual text. /// Estimate token counts from actual text.
/// Uses ~4 chars/token heuristic (standard GPT tokenizer average). /// Uses ~4 chars/token heuristic (standard GPT tokenizer average).
pub fn estimate(input_text: &str, output_text: &str) -> Self { pub fn estimate(input_text: &str, output_text: &str) -> Self {
let input_tokens = (input_text.len() as u64 + 3) / 4; let input_tokens = (input_text.len() as u64).div_ceil(4);
let output_tokens = (output_text.len() as u64 + 3) / 4; let output_tokens = (output_text.len() as u64).div_ceil(4);
Self { Self {
input_tokens, input_tokens,
input_tokens_details: InputTokensDetails { cached_tokens: 0 }, input_tokens_details: InputTokensDetails { cached_tokens: 0 },
@@ -189,14 +190,6 @@ impl Default for Usage {
} }
} }
impl Default for Reasoning {
fn default() -> Self {
Self {
effort: None,
summary: None,
}
}
}
impl Default for TextFormat { impl Default for TextFormat {
fn default() -> Self { fn default() -> Self {

View File

@@ -227,10 +227,7 @@ fn looks_like_valid_message(fields: &[ProtoField], original_len: usize) -> bool
// (e.g., a long string that happened to have a valid first-field prefix) // (e.g., a long string that happened to have a valid first-field prefix)
if fields.len() == 1 && original_len > 100 { if fields.len() == 1 && original_len > 100 {
// Single-field messages of >100 bytes are suspicious unless the field is bytes/message // Single-field messages of >100 bytes are suspicious unless the field is bytes/message
match &fields[0].value { matches!(&fields[0].value, ProtoValue::Bytes(_) | ProtoValue::Message(_))
ProtoValue::Bytes(_) | ProtoValue::Message(_) => true,
_ => false,
}
} else { } else {
true true
} }

View File

@@ -46,6 +46,7 @@ const PASSTHROUGH_DOMAINS: &[&str] = &[
]; ];
/// Configuration for the MITM proxy. /// Configuration for the MITM proxy.
#[derive(Default)]
pub struct MitmConfig { pub struct MitmConfig {
/// Port to listen on (0 = auto-assign). /// Port to listen on (0 = auto-assign).
pub port: u16, pub port: u16,
@@ -53,14 +54,6 @@ pub struct MitmConfig {
pub modify_requests: bool, pub modify_requests: bool,
} }
impl Default for MitmConfig {
fn default() -> Self {
Self {
port: 0,
modify_requests: false,
}
}
}
/// Run the MITM proxy server. /// Run the MITM proxy server.
/// ///
@@ -405,7 +398,7 @@ async fn handle_http_over_tls(
async fn resolve_upstream(domain: &str) -> String { async fn resolve_upstream(domain: &str) -> String {
// 1. Try dig @8.8.8.8 (bypasses /etc/hosts) // 1. Try dig @8.8.8.8 (bypasses /etc/hosts)
if let Ok(output) = tokio::process::Command::new("dig") if let Ok(output) = tokio::process::Command::new("dig")
.args(["+short", &format!("@8.8.8.8"), domain]) .args(["+short", "@8.8.8.8", domain])
.output() .output()
.await .await
{ {

View File

@@ -102,12 +102,11 @@ impl Snapshot {
} }
// LS process logs // LS process logs
if line.starts_with('I') || line.starts_with('W') || line.starts_with('E') { if (line.starts_with('I') || line.starts_with('W') || line.starts_with('E'))
if line.len() > 4 && line.chars().nth(1).map_or(false, |c| c.is_ascii_digit()) { && line.len() > 4 && line.chars().nth(1).is_some_and(|c| c.is_ascii_digit()) {
snap.ls_logs.push(line.to_string()); snap.ls_logs.push(line.to_string());
continue; continue;
} }
}
if line.contains("maxprocs:") { if line.contains("maxprocs:") {
snap.ls_logs.push(line.to_string()); snap.ls_logs.push(line.to_string());
continue; continue;