Skip to content

Commit 7f69371

Browse files
committed
refactor(lib): fix clippy warnings
1 parent 88f77bd commit 7f69371

File tree

7 files changed

+62
-72
lines changed

7 files changed

+62
-72
lines changed

src/bin/bench.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl BenchmarkSuite {
134134
.into_iter()
135135
.map(|(name, template_str)| {
136136
if !self.quiet {
137-
print!(" {} ... ", name);
137+
print!(" {name} ... ");
138138
}
139139
let result = self.benchmark_template(name, template_str);
140140
if !self.quiet {
@@ -180,7 +180,7 @@ impl BenchmarkSuite {
180180
.into_iter()
181181
.map(|(name, template_str)| {
182182
if !self.quiet {
183-
print!(" {} ... ", name);
183+
print!(" {name} ... ");
184184
}
185185
let result = self.benchmark_template(name, template_str);
186186
if !self.quiet {
@@ -235,7 +235,7 @@ impl BenchmarkSuite {
235235
.into_iter()
236236
.map(|(name, template_str)| {
237237
if !self.quiet {
238-
print!(" {} ... ", name);
238+
print!(" {name} ... ");
239239
}
240240
let result = self.benchmark_template(name, template_str);
241241
if !self.quiet {
@@ -290,7 +290,7 @@ impl BenchmarkSuite {
290290
.into_iter()
291291
.map(|(name, template_str)| {
292292
if !self.quiet {
293-
print!(" {} ... ", name);
293+
print!(" {name} ... ");
294294
}
295295
let result = self.benchmark_template(name, template_str);
296296
if !self.quiet {
@@ -303,13 +303,13 @@ impl BenchmarkSuite {
303303

304304
fn benchmark_template(&self, name: &str, template_str: &str) -> BenchmarkResult {
305305
let template = Template::parse(template_str)
306-
.unwrap_or_else(|e| panic!("Failed to parse template '{}': {}", template_str, e));
306+
.unwrap_or_else(|e| panic!("Failed to parse template '{template_str}': {e}"));
307307

308308
// Warmup phase - run operations without timing to warm up caches and system state
309309
for _ in 0..self.warmup_iterations {
310310
let _ = template
311311
.format(&self.test_data)
312-
.unwrap_or_else(|e| panic!("Failed to execute template '{}': {}", template_str, e));
312+
.unwrap_or_else(|e| panic!("Failed to execute template '{template_str}': {e}"));
313313
}
314314

315315
// Actual measurement phase
@@ -319,7 +319,7 @@ impl BenchmarkSuite {
319319
let start = Instant::now();
320320
let _ = template
321321
.format(&self.test_data)
322-
.unwrap_or_else(|e| panic!("Failed to execute template '{}': {}", template_str, e));
322+
.unwrap_or_else(|e| panic!("Failed to execute template '{template_str}': {e}"));
323323
let duration = start.elapsed();
324324
times.push(duration);
325325
}
@@ -331,7 +331,7 @@ impl BenchmarkSuite {
331331
fn format_duration(duration: Duration) -> String {
332332
let nanos = duration.as_nanos();
333333
if nanos < 1_000 {
334-
format!("{}ns", nanos)
334+
format!("{nanos}ns")
335335
} else if nanos < 1_000_000 {
336336
format!("{:.2}μs", nanos as f64 / 1_000.0)
337337
} else if nanos < 1_000_000_000 {
@@ -353,10 +353,7 @@ fn print_text_report(results: &[BenchmarkResult], total_time: Duration, warmup_i
353353
"• Measurement iterations per benchmark: {}",
354354
results.first().map(|r| r.iterations).unwrap_or(0)
355355
);
356-
println!(
357-
"• Warmup iterations per benchmark: {} (10% of measurements)",
358-
warmup_iterations
359-
);
356+
println!("• Warmup iterations per benchmark: {warmup_iterations} (10% of measurements)");
360357

361358
println!("\n📈 Detailed Results:");
362359
println!(

src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn read_stdin() -> Result<String, String> {
7171
let mut buffer = String::new();
7272
io::stdin()
7373
.read_to_string(&mut buffer)
74-
.map_err(|e| format!("Failed to read from stdin: {}", e))?;
74+
.map_err(|e| format!("Failed to read from stdin: {e}"))?;
7575
Ok(buffer)
7676
}
7777

@@ -87,7 +87,7 @@ fn get_template(cli: &Cli) -> Result<String, String> {
8787
(Some(template), None) => Ok(template.clone()),
8888
(None, Some(file)) => read_file(file)
8989
.map(|content| content.trim().to_string())
90-
.map_err(|e| format!("Error reading template file: {}", e)),
90+
.map_err(|e| format!("Error reading template file: {e}")),
9191
(Some(_), Some(_)) => {
9292
Err("Error: Cannot specify both template argument and template file".to_string())
9393
}
@@ -103,7 +103,7 @@ fn get_input(cli: &Cli) -> Result<String, String> {
103103
(Some(input), None) => Ok(input.clone()),
104104
(None, Some(file)) => read_file(file)
105105
.map(|content| content.trim_end().to_string())
106-
.map_err(|e| format!("Error reading input file: {}", e)),
106+
.map_err(|e| format!("Error reading input file: {e}")),
107107
(None, None) => read_stdin().map(|input| input.trim_end().to_string()),
108108
(Some(_), Some(_)) => {
109109
Err("Error: Cannot specify both input argument and input file".to_string())
@@ -224,13 +224,13 @@ fn main() {
224224

225225
// Build configuration from CLI arguments
226226
let config = build_config(cli).unwrap_or_else(|e| {
227-
eprintln!("{}", e);
227+
eprintln!("{e}");
228228
std::process::exit(1);
229229
});
230230

231231
// Parse template and handle debug mode from both template prefix and CLI flag
232232
let template = MultiTemplate::parse_with_debug(&config.template, None).unwrap_or_else(|e| {
233-
eprintln!("Error parsing template: {}", e);
233+
eprintln!("Error parsing template: {e}");
234234
std::process::exit(1);
235235
});
236236

@@ -249,10 +249,10 @@ fn main() {
249249

250250
// Process input with template
251251
let result = template.format(&config.input).unwrap_or_else(|e| {
252-
eprintln!("Error formatting input: {}", e);
252+
eprintln!("Error formatting input: {e}");
253253
std::process::exit(1);
254254
});
255255

256256
// Output result as string
257-
print!("{}", result);
257+
print!("{result}");
258258
}

src/pipeline/debug.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ impl DebugTracer {
6868
return;
6969
}
7070

71-
self.line(format!("📂 {}", session_type));
72-
self.line_with_prefix(format!("🏁 {} START", session_type), 1);
73-
self.line_with_prefix(format!("Template: {:?}", template), 1);
74-
self.line_with_prefix(format!("➡️ Input: {:?}", input), 1);
71+
self.line(format!("📂 {session_type}"));
72+
self.line_with_prefix(format!("🏁 {session_type} START"), 1);
73+
self.line_with_prefix(format!("Template: {template:?}"), 1);
74+
self.line_with_prefix(format!("➡️ Input: {input:?}"), 1);
7575
if let Some(info) = info {
7676
self.line_with_prefix(info.to_string(), 1);
7777
}
@@ -93,9 +93,9 @@ impl DebugTracer {
9393
return;
9494
}
9595

96-
self.line_with_prefix(format!("🏁 ✅ {} COMPLETE", session_type), 1);
97-
self.line_with_prefix(format!("🎯 Final result: {:?}", result), 1);
98-
self.line_with_prefix(format!("Total execution time: {:?}", elapsed), 1);
96+
self.line_with_prefix(format!("🏁 ✅ {session_type} COMPLETE"), 1);
97+
self.line_with_prefix(format!("🎯 Final result: {result:?}"), 1);
98+
self.line_with_prefix(format!("Total execution time: {elapsed:?}"), 1);
9999

100100
self.line_with_ending_prefix(
101101
format!(
@@ -179,12 +179,12 @@ impl DebugTracer {
179179
"PIPELINE"
180180
};
181181

182-
self.line_with_prefix(format!("✅ {} COMPLETE", label), depth + 1);
182+
self.line_with_prefix(format!("✅ {label} COMPLETE"), depth + 1);
183183
self.line_with_prefix(
184184
format!("🎯 Result: {}", Self::format_value(result)),
185185
depth + 1,
186186
);
187-
self.line_with_ending_prefix(format!("Time: {:?}", elapsed), depth + 1);
187+
self.line_with_ending_prefix(format!("Time: {elapsed:?}"), depth + 1);
188188

189189
if !self.is_sub_pipeline {
190190
self.separator();
@@ -231,7 +231,7 @@ impl DebugTracer {
231231
format!("🎯 Result: {}", Self::format_value(result)),
232232
depth + 1,
233233
);
234-
self.line_with_ending_prefix(format!("Time: {:?}", elapsed), depth + 1);
234+
self.line_with_ending_prefix(format!("Time: {elapsed:?}"), depth + 1);
235235
}
236236

237237
/// Logs the start of processing a map operation item.
@@ -249,8 +249,8 @@ impl DebugTracer {
249249
return;
250250
}
251251

252-
self.line_with_prefix(format!("🗂️ Item {}/{}", item_idx, total_items), 3);
253-
self.line_with_prefix(format!("➡️ Input: {:?}", input), 4);
252+
self.line_with_prefix(format!("🗂️ Item {item_idx}/{total_items}"), 3);
253+
self.line_with_prefix(format!("➡️ Input: {input:?}"), 4);
254254
}
255255

256256
/// Logs the end of processing a map operation item.
@@ -267,8 +267,8 @@ impl DebugTracer {
267267
}
268268

269269
match output {
270-
Ok(result) => self.line_with_ending_prefix(format!("Output: {:?}", result), 4),
271-
Err(error) => self.line_with_ending_prefix(format!("❌ ERROR: {}", error), 4),
270+
Ok(result) => self.line_with_ending_prefix(format!("Output: {result:?}"), 4),
271+
Err(error) => self.line_with_ending_prefix(format!("❌ ERROR: {error}"), 4),
272272
}
273273
}
274274

@@ -287,7 +287,7 @@ impl DebugTracer {
287287
}
288288

289289
self.line_with_ending_prefix(
290-
format!("📦 MAP COMPLETED: {} → {} items", input_count, output_count),
290+
format!("📦 MAP COMPLETED: {input_count} → {output_count} items"),
291291
3,
292292
);
293293
}
@@ -306,7 +306,7 @@ impl DebugTracer {
306306
return;
307307
}
308308

309-
self.line_with_prefix(format!("💾 {} {}", operation, details), 1);
309+
self.line_with_prefix(format!("💾 {operation} {details}"), 1);
310310
self.separator();
311311
}
312312

@@ -334,14 +334,11 @@ impl DebugTracer {
334334

335335
self.line_with_prefix(
336336
format!(
337-
"📊 SECTION {}/{}: [{}{}]",
338-
section_num,
339-
total_sections,
340-
section_type,
337+
"📊 SECTION {section_num}/{total_sections}: [{section_type}{}]",
341338
if content.is_empty() {
342339
String::new()
343340
} else {
344-
format!(": {}", content)
341+
format!(": {content}")
345342
}
346343
),
347344
1,
@@ -352,7 +349,7 @@ impl DebugTracer {
352349

353350
/// Outputs a debug line without indentation prefix.
354351
fn line(&self, msg: String) {
355-
eprintln!("DEBUG: {}", msg);
352+
eprintln!("DEBUG: {msg}");
356353
}
357354

358355
/// Outputs a debug line with hierarchical indentation prefix.
@@ -373,7 +370,7 @@ impl DebugTracer {
373370
6 => "│ │ │ │ │ ├── ".to_string(),
374371
_ => "│ ".repeat(depth.saturating_sub(1)) + "├── ",
375372
};
376-
eprintln!("DEBUG: {}{}", prefix, msg);
373+
eprintln!("DEBUG: {prefix}{msg}");
377374
}
378375

379376
/// Outputs a debug line with ending hierarchical prefix.
@@ -394,7 +391,7 @@ impl DebugTracer {
394391
6 => "│ │ │ │ │ └── ".to_string(),
395392
_ => "│ ".repeat(depth.saturating_sub(1)) + "└── ",
396393
};
397-
eprintln!("DEBUG: {}{}", prefix, msg);
394+
eprintln!("DEBUG: {prefix}{msg}");
398395
}
399396

400397
/// Outputs a visual separator line.
@@ -420,14 +417,14 @@ impl DebugTracer {
420417
if s.len() > 40 {
421418
format!("String({}..)", &s[..40])
422419
} else {
423-
format!("String({})", s)
420+
format!("String({s})")
424421
}
425422
}
426423
Value::List(list) => {
427424
if list.is_empty() {
428425
"List(empty)".to_string()
429426
} else if list.len() <= 3 {
430-
format!("List{:?}", list)
427+
format!("List{list:?}")
431428
} else {
432429
format!("List[{}, {}, ...+{}]", list[0], list[1], list.len() - 2)
433430
}
@@ -441,8 +438,8 @@ impl DebugTracer {
441438
/// parameters like separators and operation counts.
442439
fn format_operation(op: &StringOp) -> String {
443440
match op {
444-
StringOp::Split { sep, .. } => format!("Split('{}')", sep),
445-
StringOp::Join { sep } => format!("Join('{}')", sep),
441+
StringOp::Split { sep, .. } => format!("Split('{sep}')"),
442+
StringOp::Join { sep } => format!("Join('{sep}')"),
446443
StringOp::Map { operations } => format!("Map({})", operations.len()),
447444
_ => Self::format_operation_name(op),
448445
}

src/pipeline/mod.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn get_cached_regex(pattern: &str) -> Result<Regex, String> {
290290
}
291291

292292
// Not in cache, compile it
293-
let regex = Regex::new(pattern).map_err(|e| format!("Invalid regex: {}", e))?;
293+
let regex = Regex::new(pattern).map_err(|e| format!("Invalid regex: {e}"))?;
294294

295295
// Add to cache
296296
// Double-check in case another thread added it while we were compiling
@@ -1285,10 +1285,7 @@ where
12851285
if let Value::List(list) = val {
12861286
Ok(Value::List(transform(list)))
12871287
} else {
1288-
Err(format!(
1289-
"{} operation can only be applied to lists",
1290-
op_name
1291-
))
1288+
Err(format!("{op_name} operation can only be applied to lists"))
12921289
}
12931290
}
12941291

@@ -1376,7 +1373,7 @@ fn apply_single_operation(
13761373
}
13771374
StringOp::Filter { pattern, regex } => {
13781375
let re = regex.get_or_try_init(|| {
1379-
Regex::new(pattern).map_err(|e| format!("Invalid regex: {}", e))
1376+
Regex::new(pattern).map_err(|e| format!("Invalid regex: {e}"))
13801377
})?;
13811378
match val {
13821379
Value::List(list) => Ok(Value::List(
@@ -1387,7 +1384,7 @@ fn apply_single_operation(
13871384
}
13881385
StringOp::FilterNot { pattern, regex } => {
13891386
let re = regex.get_or_try_init(|| {
1390-
Regex::new(pattern).map_err(|e| format!("Invalid regex: {}", e))
1387+
Regex::new(pattern).map_err(|e| format!("Invalid regex: {e}"))
13911388
})?;
13921389
match val {
13931390
Value::List(list) => Ok(Value::List(
@@ -1476,7 +1473,7 @@ fn apply_single_operation(
14761473
if inline_flags.is_empty() {
14771474
pattern.clone()
14781475
} else {
1479-
format!("(?{}){}", inline_flags, pattern)
1476+
format!("(?{inline_flags}){pattern}")
14801477
}
14811478
};
14821479

@@ -1536,13 +1533,13 @@ fn apply_single_operation(
15361533
}
15371534

15381535
StringOp::Append { suffix } => {
1539-
apply_string_operation(val, |s| format!("{}{}", s, suffix), "Append")
1536+
apply_string_operation(val, |s| format!("{s}{suffix}"), "Append")
15401537
}
15411538
StringOp::Prepend { prefix } => {
1542-
apply_string_operation(val, |s| format!("{}{}", prefix, s), "Prepend")
1539+
apply_string_operation(val, |s| format!("{prefix}{s}"), "Prepend")
15431540
}
1544-
StringOp::Surround { chars } => {
1545-
apply_string_operation(val, |s| format!("{}{}{}", chars, s, chars), "Surround")
1541+
StringOp::Surround { text } => {
1542+
apply_string_operation(val, |s| format!("{text}{s}{text}"), "Surround")
15461543
}
15471544
StringOp::StripAnsi => {
15481545
if let Value::Str(s) = val {
@@ -1566,18 +1563,17 @@ fn apply_single_operation(
15661563
let padding_needed = *width - current_len;
15671564
match direction {
15681565
PadDirection::Left => {
1569-
format!("{}{}", char.to_string().repeat(padding_needed), s)
1566+
format!("{}{s}", char.to_string().repeat(padding_needed))
15701567
}
15711568
PadDirection::Right => {
1572-
format!("{}{}", s, char.to_string().repeat(padding_needed))
1569+
format!("{s}{}", char.to_string().repeat(padding_needed))
15731570
}
15741571
PadDirection::Both => {
15751572
let left_pad = padding_needed / 2;
15761573
let right_pad = padding_needed - left_pad;
15771574
format!(
1578-
"{}{}{}",
1575+
"{}{s}{}",
15791576
char.to_string().repeat(left_pad),
1580-
s,
15811577
char.to_string().repeat(right_pad)
15821578
)
15831579
}
@@ -1598,7 +1594,7 @@ fn apply_single_operation(
15981594
} => {
15991595
if let Value::Str(s) = val {
16001596
let re = regex.get_or_try_init(|| {
1601-
Regex::new(pattern).map_err(|e| format!("Invalid regex: {}", e))
1597+
Regex::new(pattern).map_err(|e| format!("Invalid regex: {e}"))
16021598
})?;
16031599
let result = if let Some(group_idx) = group {
16041600
re.captures(&s)

0 commit comments

Comments
 (0)