Skip to content

Commit ff60dda

Browse files
committed
Fix all clippy complaints
1 parent f7b639a commit ff60dda

8 files changed

Lines changed: 36 additions & 41 deletions

File tree

src/llm_engine/anthropic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ impl Anthropic {
3838

3939
impl LLMEngine for Anthropic {
4040
fn new(options: &OptionMap) -> Self {
41-
let api_key = option_or_env(&options, "api_key", "ANTHROPIC_API_KEY");
42-
let base_url = option_or_env_fallback(&options, "base_url", "ANTHROPIC_BASE_URL", "https://api.anthropic.com");
41+
let api_key = option_or_env(options, "api_key", "ANTHROPIC_API_KEY");
42+
let base_url = option_or_env_fallback(options, "base_url", "ANTHROPIC_BASE_URL", "https://api.anthropic.com");
4343
let model = options.get("model").unwrap().to_string();
44-
let web_search = options.get("web_search").map_or(false, |v| v == "true");
45-
let thinking = options.get("thinking").map_or(false, |v| v == "true");
44+
let web_search = options.get("web_search").is_some_and(|v| v == "true");
45+
let thinking = options.get("thinking").is_some_and(|v| v == "true");
4646
let thinking_tokens = options.get("thinking_tokens").and_then(|v| v.parse::<u32>().ok()).unwrap_or(5000);
4747

4848
Self {
@@ -88,7 +88,7 @@ impl LLMEngine for Anthropic {
8888
}
8989

9090
fn execute(&mut self) -> Result<()> {
91-
let mut tool_definitions = self.tools.iter().map(|tool| Self::anthropic_tool_definition(tool)).collect::<Vec<_>>();
91+
let mut tool_definitions = self.tools.iter().map(Self::anthropic_tool_definition).collect::<Vec<_>>();
9292

9393
// Add web search tool if enabled
9494
if self.web_search {

src/llm_engine/google.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ impl Google {
3535

3636
impl LLMEngine for Google {
3737
fn new(options: &OptionMap) -> Self {
38-
let api_key = option_or_env(&options, "api_key", "GOOGLE_API_KEY");
39-
let base_url = option_or_env_fallback(&options, "base_url", "GOOGLE_BASE_URL", "https://generativelanguage.googleapis.com");
38+
let api_key = option_or_env(options, "api_key", "GOOGLE_API_KEY");
39+
let base_url = option_or_env_fallback(options, "base_url", "GOOGLE_BASE_URL", "https://generativelanguage.googleapis.com");
4040
let model = options.get("model").unwrap().to_string();
4141

4242
Self {
@@ -81,7 +81,7 @@ impl LLMEngine for Google {
8181
"role": "user",
8282
"parts": self.content
8383
}],
84-
"tools": [{ "function_declarations": self.tools.iter().map(|tool| Self::google_tool_definition(tool)).collect::<Vec<_>>() }],
84+
"tools": [{ "function_declarations": self.tools.iter().map(Self::google_tool_definition).collect::<Vec<_>>() }],
8585
"tool_config": {
8686
"function_calling_config": {
8787
"mode": "ANY"

src/llm_engine/openai.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl OpenAI {
3838

3939
impl LLMEngine for OpenAI {
4040
fn new(options: &OptionMap) -> Self {
41-
let api_key = option_or_env(&options, "api_key", "OPENAI_API_KEY");
42-
let base_url = option_or_env_fallback(&options, "base_url", "OPENAI_BASE_URL", "https://api.openai.com");
41+
let api_key = option_or_env(options, "api_key", "OPENAI_API_KEY");
42+
let base_url = option_or_env_fallback(options, "base_url", "OPENAI_BASE_URL", "https://api.openai.com");
4343
let model = options.get("model").unwrap().to_string();
4444

4545
Self {
@@ -86,7 +86,7 @@ impl LLMEngine for OpenAI {
8686
"role": "user",
8787
"content": self.content
8888
}],
89-
"tools": self.tools.iter().map(|tool| Self::openai_tool_definition(tool)).collect::<Vec<_>>(),
89+
"tools": self.tools.iter().map(Self::openai_tool_definition).collect::<Vec<_>>(),
9090
"tool_choice": "required",
9191
"parallel_tool_calls": false
9292
});

src/main.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use anyhow::Result;
22
use base64::prelude::*;
33
use clap::Parser;
44
use dotenv::dotenv;
5-
use env_logger;
65
use log::{debug, info};
76
use serde_json::Value as json;
87
use std::sync::{Arc, Mutex};
@@ -195,16 +194,14 @@ fn ghostwriter(args: &Args) -> Result<()> {
195194

196195
let engine_name = if let Some(engine) = args.engine.clone() {
197196
engine.to_string()
197+
} else if model.starts_with("gpt") {
198+
"openai".to_string()
199+
} else if model.starts_with("claude") {
200+
"anthropic".to_string()
201+
} else if model.starts_with("gemini") {
202+
"google".to_string()
198203
} else {
199-
if model.starts_with("gpt") {
200-
"openai".to_string()
201-
} else if model.starts_with("claude") {
202-
"anthropic".to_string()
203-
} else if model.starts_with("gemini") {
204-
"google".to_string()
205-
} else {
206-
panic!("Unable to guess engine from model name {}", model)
207-
}
204+
panic!("Unable to guess engine from model name {}", model)
208205
};
209206
debug!("Engine: {}", engine_name);
210207

src/pen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Pen {
7272
Ok(())
7373
}
7474

75-
pub fn draw_bitmap(&mut self, bitmap: &Vec<Vec<bool>>) -> Result<()> {
75+
pub fn draw_bitmap(&mut self, bitmap: &[Vec<bool>]) -> Result<()> {
7676
let mut is_pen_down = false;
7777
for (y, row) in bitmap.iter().enumerate() {
7878
for (x, &pixel) in row.iter().enumerate() {

src/screenshot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Screenshot {
7474
fn find_xochitl_pid() -> Result<String> {
7575
let output = process::Command::new("pidof").arg("xochitl").output()?;
7676
let pids = String::from_utf8(output.stdout)?;
77-
for pid in pids.split_whitespace() {
77+
if let Some(pid) = pids.split_whitespace().next() {
7878
return Ok(pid.to_string());
7979
// let has_fb = process::Command::new("grep")
8080
// .args(&["-C1", "/dev/fb0", &format!("/proc/{}/maps", pid)])
@@ -152,7 +152,7 @@ impl Screenshot {
152152

153153
while length < screen_size_bytes {
154154
// debug!("looping while {} < {}", length, screen_size_bytes);
155-
offset += (length - 2) as u64;
155+
offset += length - 2;
156156

157157
// debug!(" ... trying {}", start_address + offset + 8);
158158
file.seek(std::io::SeekFrom::Start(start_address + offset + 8))?;

src/touch.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ impl Touch {
6464
if event.code() == ABS_MT_POSITION_Y {
6565
position_y = event.value();
6666
}
67-
if event.code() == ABS_MT_TRACKING_ID {
68-
if event.value() == -1 {
69-
let (x, y) = self.input_to_virtual((position_x, position_y));
70-
debug!("Touch release detected at ({}, {}) normalized ({}, {})", position_x, position_y, x, y);
71-
if x > 700 && y < 50 {
72-
debug!("Touch release in target zone!");
73-
return Ok(());
74-
}
67+
if event.code() == ABS_MT_TRACKING_ID && event.value() == -1 {
68+
let (x, y) = self.input_to_virtual((position_x, position_y));
69+
debug!("Touch release detected at ({}, {}) normalized ({}, {})", position_x, position_y, x, y);
70+
if x > 700 && y < 50 {
71+
debug!("Touch release in target zone!");
72+
return Ok(());
7573
}
7674
}
7775
}

src/util.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn svg_to_bitmap(svg_data: &str, width: u32, height: u32) -> Result<Vec<Vec<
4545
Ok(bitmap)
4646
}
4747

48-
pub fn write_bitmap_to_file(bitmap: &Vec<Vec<bool>>, filename: &str) -> Result<()> {
48+
pub fn write_bitmap_to_file(bitmap: &[Vec<bool>], filename: &str) -> Result<()> {
4949
let width = bitmap[0].len();
5050
let height = bitmap.len();
5151
let mut img = GrayImage::new(width as u32, height as u32);
@@ -63,19 +63,19 @@ pub fn write_bitmap_to_file(bitmap: &Vec<Vec<bool>>, filename: &str) -> Result<(
6363

6464
pub fn option_or_env(options: &OptionMap, key: &str, env_key: &str) -> String {
6565
let option = options.get(key);
66-
if option.is_some() {
67-
option.unwrap().to_string()
66+
if let Some(value) = option {
67+
value.to_string()
6868
} else {
69-
std::env::var(env_key.to_string()).unwrap().to_string()
69+
std::env::var(env_key).unwrap().to_string()
7070
}
7171
}
7272

7373
pub fn option_or_env_fallback(options: &OptionMap, key: &str, env_key: &str, fallback: &str) -> String {
7474
let option = options.get(key);
75-
if option.is_some() {
76-
option.unwrap().to_string()
75+
if let Some(value) = option {
76+
value.to_string()
7777
} else {
78-
std::env::var(env_key.to_string()).unwrap_or(fallback.to_string()).to_string()
78+
std::env::var(env_key).unwrap_or_else(|_| fallback.to_string())
7979
}
8080
}
8181

@@ -104,7 +104,7 @@ pub fn setup_uinput() -> Result<()> {
104104
dotenv::from_path(os_info_path)?;
105105
}
106106

107-
let img_version = std::env::var("IMG_VERSION".to_string()).unwrap_or_default();
107+
let img_version = std::env::var("IMG_VERSION").unwrap_or_default();
108108

109109
if img_version.is_empty() {
110110
return Ok(());
@@ -115,7 +115,7 @@ pub fn setup_uinput() -> Result<()> {
115115
// let target_module_filename = format!("rmpp/uinput-{short_version}.ko");
116116

117117
// Use the function from embedded_assets module to get the module data
118-
let uinput_module_data = get_uinput_module_data(&short_version).expect(&format!("Uinput module for version {} not found", short_version));
118+
let uinput_module_data = get_uinput_module_data(&short_version).unwrap_or_else(|| panic!("Uinput module for version {} not found", short_version));
119119
let raw_uinput_module_data = uinput_module_data.as_slice();
120120
let mut uinput_module_file = std::fs::File::create("/tmp/uinput.ko")?;
121121
uinput_module_file.write_all(raw_uinput_module_data)?;

0 commit comments

Comments
 (0)