generated from nhcarrigan/template
fix: resolve Clippy 1.95 warnings in sessions.rs and wsl_bridge.rs
Replaces sort_by with sort_by_key + Reverse for unnecessary_sort_by lint, and replaces manual > 0 guard before division with checked_div for manual_checked_ops lint.
This commit is contained in:
@@ -81,7 +81,7 @@ pub async fn list_sessions(app: AppHandle) -> Result<Vec<SessionListItem>, Strin
|
||||
let mut items: Vec<SessionListItem> = sessions.iter().map(SessionListItem::from).collect();
|
||||
|
||||
// Sort by last activity, most recent first
|
||||
items.sort_by(|a, b| b.last_activity_at.cmp(&a.last_activity_at));
|
||||
items.sort_by_key(|b| std::cmp::Reverse(b.last_activity_at));
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ pub async fn search_sessions(app: AppHandle, query: String) -> Result<Vec<Sessio
|
||||
.collect();
|
||||
|
||||
// Sort by last activity, most recent first
|
||||
matching.sort_by(|a, b| b.last_activity_at.cmp(&a.last_activity_at));
|
||||
matching.sort_by_key(|b| std::cmp::Reverse(b.last_activity_at));
|
||||
|
||||
Ok(matching)
|
||||
}
|
||||
@@ -348,7 +348,7 @@ mod tests {
|
||||
];
|
||||
|
||||
// Sort by last activity, most recent first (mimics list_sessions behavior)
|
||||
sessions.sort_by(|a, b| b.last_activity_at.cmp(&a.last_activity_at));
|
||||
sessions.sort_by_key(|b| std::cmp::Reverse(b.last_activity_at));
|
||||
|
||||
assert_eq!(sessions[0].id, "new");
|
||||
assert_eq!(sessions[1].id, "old");
|
||||
|
||||
@@ -920,10 +920,9 @@ impl WslBridge {
|
||||
let stats = self.stats.read();
|
||||
for tool_name in &tools {
|
||||
if let Some(tool_stats) = stats.session_tools_usage.get(tool_name) {
|
||||
if tool_stats.call_count > 0 {
|
||||
// Use session average tokens per call for this tool
|
||||
let avg_tokens = (tool_stats.estimated_input_tokens + tool_stats.estimated_output_tokens)
|
||||
/ tool_stats.call_count;
|
||||
if let Some(avg_tokens) = (tool_stats.estimated_input_tokens + tool_stats.estimated_output_tokens)
|
||||
.checked_div(tool_stats.call_count)
|
||||
{
|
||||
tool_overhead_tokens += avg_tokens;
|
||||
tracing::info!("[COST ESTIMATION] Tool {} average: {} tokens", tool_name, avg_tokens);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user