cargo-mate 1.8.0

Rust development companion that enhances cargo with intelligent workflows, state management, performance optimization, and comprehensive project monitoring.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
use super::{Tool, Result, ToolError, common_options, parse_output_format, OutputFormat};
use clap::{Arg, ArgMatches, Command};
use colored::*;
use std::path::Path;
use std::fs;
use std::collections::HashMap;
use syn::{parse_file, parse2, Item, ItemStruct, Fields, Field, Type, Attribute, Meta};
use quote::quote;
use serde_json::{Value, Map};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
pub struct SerdeValidatorTool;
#[derive(Debug, Clone, Serialize, Deserialize)]
struct ValidationReport {
    structs_analyzed: usize,
    fields_analyzed: usize,
    serialization_issues: Vec<SerializationIssue>,
    deserialization_issues: Vec<DeserializationIssue>,
    suggestions: Vec<String>,
    test_cases_generated: Vec<String>,
    timestamp: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct SerializationIssue {
    struct_name: String,
    field_name: String,
    issue_type: String,
    description: String,
    severity: String,
    suggestion: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct DeserializationIssue {
    struct_name: String,
    field_name: String,
    issue_type: String,
    description: String,
    severity: String,
    suggestion: String,
}
#[derive(Debug, Clone)]
struct StructAnalysis {
    name: String,
    fields: Vec<FieldAnalysis>,
    has_derive_serde: bool,
    has_serialize: bool,
    has_deserialize: bool,
}
#[derive(Debug, Clone)]
struct FieldAnalysis {
    name: String,
    ty: String,
    has_serde_attrs: Vec<String>,
    is_optional: bool,
    default_value: Option<String>,
    rename: Option<String>,
    skip_serializing: bool,
    skip_deserializing: bool,
}
impl SerdeValidatorTool {
    pub fn new() -> Self {
        Self
    }
    fn analyze_rust_code(&self, file_path: &str) -> Result<Vec<StructAnalysis>> {
        let content = fs::read_to_string(file_path)?;
        let syntax = parse_file(&content)?;
        let mut structs = Vec::new();
        for item in syntax.items {
            if let Item::Struct(struct_def) = item {
                let analysis = self.analyze_struct(&struct_def)?;
                structs.push(analysis);
            }
        }
        Ok(structs)
    }
    fn analyze_struct(&self, struct_def: &syn::ItemStruct) -> Result<StructAnalysis> {
        let name = struct_def.ident.to_string();
        let mut has_derive_serde = false;
        let mut has_serialize = false;
        let mut has_deserialize = false;
        for attr in &struct_def.attrs {
            if attr.path().segments.last().unwrap().ident == "derive" {
                if let Ok(Meta::List(meta_list)) = attr.parse_args::<syn::Meta>() {
                    has_serialize = true;
                    has_deserialize = true;
                }
            }
        }
        let mut fields = Vec::new();
        if let syn::Fields::Named(named_fields) = &struct_def.fields {
            for field in &named_fields.named {
                let field_analysis = self.analyze_field(field)?;
                fields.push(field_analysis);
            }
        }
        Ok(StructAnalysis {
            name,
            fields,
            has_derive_serde,
            has_serialize,
            has_deserialize,
        })
    }
    fn analyze_field(&self, field: &Field) -> Result<FieldAnalysis> {
        let name = field.ident.as_ref().unwrap().to_string();
        let ty = quote!(# field.ty).to_string();
        let mut has_serde_attrs = Vec::new();
        let mut is_optional = false;
        let mut default_value = None;
        let mut rename = None;
        let mut skip_serializing = false;
        let mut skip_deserializing = false;
        if ty.starts_with("Option <") || ty.starts_with("std::option::Option<") {
            is_optional = true;
        }
        for attr in &field.attrs {
            if attr.path().segments.last().unwrap().ident == "serde" {
                has_serde_attrs.push(quote!(# attr).to_string());
                if let Ok(Meta::List(meta_list)) = attr.parse_args::<syn::Meta>() {
                    has_serde_attrs.push("serde_attr_detected".to_string());
                }
            }
        }
        Ok(FieldAnalysis {
            name,
            ty,
            has_serde_attrs,
            is_optional,
            default_value,
            rename,
            skip_serializing,
            skip_deserializing,
        })
    }
    fn validate_serialization(
        &self,
        structs: &[StructAnalysis],
    ) -> Vec<SerializationIssue> {
        let mut issues = Vec::new();
        for struct_analysis in structs {
            if !struct_analysis.has_serialize && !struct_analysis.has_derive_serde {
                issues
                    .push(SerializationIssue {
                        struct_name: struct_analysis.name.clone(),
                        field_name: "struct".to_string(),
                        issue_type: "missing_serialize_derive".to_string(),
                        description: "Struct does not derive Serialize".to_string(),
                        severity: "warning".to_string(),
                        suggestion: "Add #[derive(Serialize)] to the struct".to_string(),
                    });
                continue;
            }
            for field in &struct_analysis.fields {
                if field.ty.contains("std::sync::Mutex")
                    || field.ty.contains("std::rc::Rc")
                {
                    issues
                        .push(SerializationIssue {
                            struct_name: struct_analysis.name.clone(),
                            field_name: field.name.clone(),
                            issue_type: "non_serializable_type".to_string(),
                            description: format!(
                                "Field type {} is not serializable", field.ty
                            ),
                            severity: "error".to_string(),
                            suggestion: "Use a serializable type or add #[serde(skip)]"
                                .to_string(),
                        });
                }
                if field.skip_serializing && !field.is_optional
                    && field.default_value.is_none()
                {
                    issues
                        .push(SerializationIssue {
                            struct_name: struct_analysis.name.clone(),
                            field_name: field.name.clone(),
                            issue_type: "skipped_required_field".to_string(),
                            description: "Required field is skipped during serialization"
                                .to_string(),
                            severity: "warning".to_string(),
                            suggestion: "Add a default value or make the field optional"
                                .to_string(),
                        });
                }
                if field.skip_serializing != field.skip_deserializing {
                    issues
                        .push(SerializationIssue {
                            struct_name: struct_analysis.name.clone(),
                            field_name: field.name.clone(),
                            issue_type: "inconsistent_skip".to_string(),
                            description: "Field has different skip settings for serialize/deserialize"
                                .to_string(),
                            severity: "info".to_string(),
                            suggestion: "Use #[serde(skip)] for both or specify separately"
                                .to_string(),
                        });
                }
            }
        }
        issues
    }
    fn validate_deserialization(
        &self,
        structs: &[StructAnalysis],
    ) -> Vec<DeserializationIssue> {
        let mut issues = Vec::new();
        for struct_analysis in structs {
            if !struct_analysis.has_deserialize && !struct_analysis.has_derive_serde {
                issues
                    .push(DeserializationIssue {
                        struct_name: struct_analysis.name.clone(),
                        field_name: "struct".to_string(),
                        issue_type: "missing_deserialize_derive".to_string(),
                        description: "Struct does not derive Deserialize".to_string(),
                        severity: "warning".to_string(),
                        suggestion: "Add #[derive(Deserialize)] to the struct"
                            .to_string(),
                    });
                continue;
            }
            for field in &struct_analysis.fields {
                if field.ty.contains("std::sync::Mutex")
                    || field.ty.contains("std::rc::Rc")
                {
                    issues
                        .push(DeserializationIssue {
                            struct_name: struct_analysis.name.clone(),
                            field_name: field.name.clone(),
                            issue_type: "non_deserializable_type".to_string(),
                            description: format!(
                                "Field type {} is not deserializable", field.ty
                            ),
                            severity: "error".to_string(),
                            suggestion: "Use a deserializable type or add #[serde(skip)]"
                                .to_string(),
                        });
                }
                if !field.is_optional && field.default_value.is_none()
                    && field.skip_deserializing
                {
                    issues
                        .push(DeserializationIssue {
                            struct_name: struct_analysis.name.clone(),
                            field_name: field.name.clone(),
                            issue_type: "required_field_skipped".to_string(),
                            description: "Required field is skipped during deserialization"
                                .to_string(),
                            severity: "error".to_string(),
                            suggestion: "Add a default value or make the field optional"
                                .to_string(),
                        });
                }
                if let Some(rename_val) = &field.rename {
                    if rename_val.contains(" ") || rename_val.contains("-") {
                        issues
                            .push(DeserializationIssue {
                                struct_name: struct_analysis.name.clone(),
                                field_name: field.name.clone(),
                                issue_type: "complex_rename".to_string(),
                                description: format!(
                                    "Complex rename pattern: {}", rename_val
                                ),
                                severity: "info".to_string(),
                                suggestion: "Consider using simpler field names in JSON"
                                    .to_string(),
                            });
                    }
                }
            }
        }
        issues
    }
    fn generate_test_cases(&self, structs: &[StructAnalysis]) -> Vec<String> {
        let mut test_cases = Vec::new();
        for struct_analysis in structs {
            if !struct_analysis.has_serialize || !struct_analysis.has_deserialize {
                continue;
            }
            let test_name = format!(
                "test_{}_serde", struct_analysis.name.to_lowercase()
            );
            let mut test_code = format!("#[test]\nfn {}() {{\n", test_name);
            test_code
                .push_str(&format!("    let test_data = {} {{\n", struct_analysis.name));
            for field in &struct_analysis.fields {
                if field.skip_serializing || field.skip_deserializing {
                    continue;
                }
                let test_value = self.generate_test_value(field);
                test_code
                    .push_str(&format!("        {}: {},\n", field.name, test_value));
            }
            test_code.push_str("    };\n\n");
            test_code.push_str("    // Test serialization\n");
            test_code
                .push_str(
                    "    let serialized = serde_json::to_string(&test_data).unwrap();\n",
                );
            test_code.push_str("    println!(\"Serialized: {{}}\", serialized);\n\n");
            test_code.push_str("    // Test deserialization\n");
            test_code
                .push_str(
                    &format!(
                        "    let deserialized: {} = serde_json::from_str(&serialized).unwrap();\n",
                        struct_analysis.name
                    ),
                );
            test_code.push_str("    assert_eq!(test_data, deserialized);\n");
            test_code.push_str("}\n\n");
            test_cases.push(test_code);
        }
        test_cases
    }
    fn generate_test_value(&self, field: &FieldAnalysis) -> String {
        if field.is_optional {
            return "None".to_string();
        }
        if let Some(default) = &field.default_value {
            return default.clone();
        }
        if field.ty.contains("String") {
            "\"test_value\"".to_string()
        } else if field.ty.contains("i32") || field.ty.contains("i64") {
            "42".to_string()
        } else if field.ty.contains("u32") || field.ty.contains("u64") {
            "42".to_string()
        } else if field.ty.contains("bool") {
            "true".to_string()
        } else if field.ty.contains("f32") || field.ty.contains("f64") {
            "3.14".to_string()
        } else if field.ty.contains("Vec") {
            "vec![]".to_string()
        } else if field.ty.contains("HashMap") {
            "std::collections::HashMap::new()".to_string()
        } else {
            format!("{}::default()", field.ty)
        }
    }
    fn generate_suggestions(
        &self,
        structs: &[StructAnalysis],
        serialization_issues: &[SerializationIssue],
        deserialization_issues: &[DeserializationIssue],
    ) -> Vec<String> {
        let mut suggestions = Vec::new();
        if structs.iter().any(|s| !s.has_serialize && !s.has_derive_serde) {
            suggestions
                .push(
                    "Add #[derive(Serialize)] to structs that need JSON serialization"
                        .to_string(),
                );
        }
        if structs.iter().any(|s| !s.has_deserialize && !s.has_derive_serde) {
            suggestions
                .push(
                    "Add #[derive(Deserialize)] to structs that need JSON deserialization"
                        .to_string(),
                );
        }
        if serialization_issues.iter().any(|i| i.issue_type == "non_serializable_type") {
            suggestions
                .push(
                    "Replace non-serializable types (Mutex, Rc) with serializable alternatives"
                        .to_string(),
                );
        }
        if deserialization_issues
            .iter()
            .any(|i| i.issue_type == "non_deserializable_type")
        {
            suggestions
                .push(
                    "Use deserializable types or implement custom deserialization"
                        .to_string(),
                );
        }
        suggestions
            .push(
                "Use #[serde(rename_all = \"camelCase\")] for consistent field naming"
                    .to_string(),
            );
        suggestions
            .push(
                "Add #[serde(default)] to optional fields for forward compatibility"
                    .to_string(),
            );
        suggestions
            .push(
                "Use #[serde(skip)] for fields that shouldn't be serialized".to_string(),
            );
        suggestions
    }
    fn display_report(
        &self,
        report: &ValidationReport,
        output_format: OutputFormat,
        verbose: bool,
    ) {
        match output_format {
            OutputFormat::Human => {
                println!(
                    "\n🔍 {} - Serde Validation Report", "CargoMate SerdeValidator"
                    .bold().blue()
                );
                println!("{}", "".repeat(60).blue());
                println!("\n📊 Summary:");
                println!("  • Structs Analyzed: {}", report.structs_analyzed);
                println!("  • Fields Analyzed: {}", report.fields_analyzed);
                println!(
                    "  • Serialization Issues: {}", report.serialization_issues.len()
                );
                println!(
                    "  • Deserialization Issues: {}", report.deserialization_issues
                    .len()
                );
                println!(
                    "  • Test Cases Generated: {}", report.test_cases_generated.len()
                );
                if !report.serialization_issues.is_empty() {
                    println!("\n⚠️  Serialization Issues:");
                    for issue in &report.serialization_issues {
                        let severity_icon = match issue.severity.as_str() {
                            "error" => "",
                            "warning" => "⚠️",
                            "info" => "ℹ️",
                            _ => "",
                        };
                        println!(
                            "  {} {}::{} - {}", severity_icon, issue.struct_name, issue
                            .field_name, issue.description
                        );
                        if verbose {
                            println!("    💡 {}", issue.suggestion);
                        }
                    }
                }
                if !report.deserialization_issues.is_empty() {
                    println!("\n⚠️  Deserialization Issues:");
                    for issue in &report.deserialization_issues {
                        let severity_icon = match issue.severity.as_str() {
                            "error" => "",
                            "warning" => "⚠️",
                            "info" => "ℹ️",
                            _ => "",
                        };
                        println!(
                            "  {} {}::{} - {}", severity_icon, issue.struct_name, issue
                            .field_name, issue.description
                        );
                        if verbose {
                            println!("    💡 {}", issue.suggestion);
                        }
                    }
                }
                if verbose && !report.test_cases_generated.is_empty() {
                    println!("\n🧪 Generated Test Cases:");
                    for test_case in &report.test_cases_generated {
                        println!("  {}", test_case.lines().next().unwrap_or(""));
                    }
                }
                if !report.suggestions.is_empty() {
                    println!("\n💡 Suggestions:");
                    for suggestion in &report.suggestions {
                        println!("{}", suggestion.cyan());
                    }
                }
                println!("\n✅ Validation complete!");
                if report.serialization_issues.is_empty()
                    && report.deserialization_issues.is_empty()
                {
                    println!("   All structs are properly configured for Serde!");
                }
            }
            OutputFormat::Json => {
                let json = serde_json::to_string_pretty(report)
                    .unwrap_or_else(|_| "{}".to_string());
                println!("{}", json);
            }
            OutputFormat::Table => {
                println!(
                    "{:<25} {:<20} {:<15} {:<15}", "Struct", "Serialization",
                    "Deserialization", "Total Issues"
                );
                println!("{}", "".repeat(80));
                let mut struct_issues = HashMap::new();
                for issue in &report.serialization_issues {
                    let entry = struct_issues
                        .entry(&issue.struct_name)
                        .or_insert((0, 0));
                    entry.0 += 1;
                }
                for issue in &report.deserialization_issues {
                    let entry = struct_issues
                        .entry(&issue.struct_name)
                        .or_insert((0, 0));
                    entry.1 += 1;
                }
                for (struct_name, (ser_issues, deser_issues)) in struct_issues {
                    let total = ser_issues + deser_issues;
                    println!(
                        "{:<25} {:<20} {:<15} {:<15}", struct_name, ser_issues
                        .to_string(), deser_issues.to_string(), total.to_string()
                    );
                }
            }
        }
    }
}
impl Tool for SerdeValidatorTool {
    fn name(&self) -> &'static str {
        "serde-validator"
    }
    fn description(&self) -> &'static str {
        "Validate serde serialization/deserialization"
    }
    fn command(&self) -> Command {
        Command::new(self.name())
            .about(self.description())
            .long_about(
                "Analyze Rust structs for proper Serde serialization/deserialization setup. \
                        Detects common issues and generates test cases.

EXAMPLES:
    cm tool serde-validator --input src/models.rs
    cm tool serde-validator --workspace --generate-tests
    cm tool serde-validator --input src/api.rs --fix",
            )
            .args(
                &[
                    Arg::new("input")
                        .long("input")
                        .short('i')
                        .help("Input Rust file to analyze")
                        .required(true),
                    Arg::new("workspace")
                        .long("workspace")
                        .help("Analyze all Rust files in workspace")
                        .action(clap::ArgAction::SetTrue),
                    Arg::new("generate-tests")
                        .long("generate-tests")
                        .help("Generate test cases for validated structs")
                        .action(clap::ArgAction::SetTrue),
                    Arg::new("output")
                        .long("output")
                        .short('o')
                        .help("Output file for generated tests")
                        .default_value("tests/serde_tests.rs"),
                    Arg::new("fix")
                        .long("fix")
                        .help("Automatically fix simple issues")
                        .action(clap::ArgAction::SetTrue),
                    Arg::new("format")
                        .long("format")
                        .short('f')
                        .help("Serialization format to validate")
                        .default_value("json")
                        .value_parser(["json", "toml", "yaml", "bincode"]),
                ],
            )
            .args(&common_options())
    }
    fn execute(&self, matches: &ArgMatches) -> Result<()> {
        let input = matches.get_one::<String>("input");
        let workspace = matches.get_flag("workspace");
        let generate_tests = matches.get_flag("generate-tests");
        let output_file = matches.get_one::<String>("output").unwrap();
        let fix = matches.get_flag("fix");
        let format = matches.get_one::<String>("format").unwrap();
        let output_format = parse_output_format(matches);
        let verbose = matches.get_flag("verbose");
        println!(
            "🔍 {} - Validating Serde Configuration", "CargoMate SerdeValidator".bold()
            .blue()
        );
        let mut all_structs = Vec::new();
        if workspace {
            let rust_files = self.find_rust_files(".")?;
            for file_path in rust_files {
                if let Ok(structs) = self.analyze_rust_code(&file_path) {
                    all_structs.extend(structs);
                }
            }
        } else if let Some(input_file) = input {
            if !Path::new(input_file).exists() {
                return Err(
                    ToolError::InvalidArguments(
                        format!("Input file {} not found", input_file),
                    ),
                );
            }
            all_structs = self.analyze_rust_code(input_file)?;
        } else {
            return Err(
                ToolError::InvalidArguments(
                    "Either specify an input file or use --workspace".to_string(),
                ),
            );
        }
        if all_structs.is_empty() {
            println!("{}", "No structs found to analyze".yellow());
            return Ok(());
        }
        if verbose {
            println!("\n📋 Found {} struct(s):", all_structs.len());
            for struct_analysis in &all_structs {
                let serde_status = if struct_analysis.has_serialize
                    && struct_analysis.has_deserialize
                {
                    "✅ Serde ready"
                } else if struct_analysis.has_serialize {
                    "📤 Serialize only"
                } else if struct_analysis.has_deserialize {
                    "📥 Deserialize only"
                } else {
                    "❌ No Serde"
                };
                println!(
                    "{} - {} field(s) - {}", struct_analysis.name.green(),
                    struct_analysis.fields.len(), serde_status
                );
            }
        }
        let serialization_issues = self.validate_serialization(&all_structs);
        let deserialization_issues = self.validate_deserialization(&all_structs);
        let test_cases = if generate_tests {
            self.generate_test_cases(&all_structs)
        } else {
            Vec::new()
        };
        let suggestions = self
            .generate_suggestions(
                &all_structs,
                &serialization_issues,
                &deserialization_issues,
            );
        let total_fields = all_structs.iter().map(|s| s.fields.len()).sum();
        let report = ValidationReport {
            structs_analyzed: all_structs.len(),
            fields_analyzed: total_fields,
            serialization_issues,
            deserialization_issues,
            suggestions,
            test_cases_generated: test_cases.clone(),
            timestamp: chrono::Utc::now().to_rfc3339(),
        };
        if generate_tests && !test_cases.is_empty() {
            let test_file_content = self.generate_test_file(&test_cases, format);
            fs::create_dir_all(
                Path::new(output_file).parent().unwrap_or(Path::new(".")),
            )?;
            fs::write(output_file, test_file_content)?;
            println!("\n✅ Generated test file: {}", output_file);
        }
        self.display_report(&report, output_format, verbose);
        if fix
            && (!report.serialization_issues.is_empty()
                || !report.deserialization_issues.is_empty())
        {
            println!("\n🔧 Auto-fix feature not yet implemented");
            println!("   Manual fixes recommended based on the suggestions above");
        }
        Ok(())
    }
}
impl SerdeValidatorTool {
    fn find_rust_files(&self, dir: &str) -> Result<Vec<String>> {
        let mut files = Vec::new();
        self.find_rust_files_recursive(dir, &mut files)?;
        Ok(files)
    }
    fn find_rust_files_recursive(
        &self,
        dir: &str,
        files: &mut Vec<String>,
    ) -> Result<()> {
        let path = Path::new(dir);
        if !path.exists() {
            return Ok(());
        }
        for entry in fs::read_dir(path)? {
            let entry = entry?;
            let path = entry.path();
            if path.is_dir() {
                let dir_name = path.file_name().unwrap_or_default().to_string_lossy();
                if !matches!(dir_name.as_ref(), "target" | ".git" | "node_modules") {
                    self.find_rust_files_recursive(&path.to_string_lossy(), files)?;
                }
            } else if let Some(ext) = path.extension() {
                if ext == "rs" {
                    files.push(path.to_string_lossy().to_string());
                }
            }
        }
        Ok(())
    }
    fn generate_test_file(&self, test_cases: &[String], format: &str) -> String {
        let mut content = format!(
            "//! Auto-generated Serde validation tests
//! Generated by CargoMate SerdeValidator
//! Format: {}

use serde::{{Deserialize, Serialize}};

",
            format
        );
        for test_case in test_cases {
            content.push_str(test_case);
        }
        content
    }
}
impl Default for SerdeValidatorTool {
    fn default() -> Self {
        Self::new()
    }
}