# Rustfmt Configuration for Foxhunt HFT System # IMPORT STANDARDIZATION AND TYPE GOVERNANCE SUPPORT # ============================================================================= # ๐ŸŽฏ IMPORT ORGANIZATION - CRITICAL FOR TYPE GOVERNANCE # ============================================================================= # Group imports to enforce canonical type usage patterns imports_granularity = "Module" # Group by module for clarity group_imports = "StdExternalCrate" # Separate std, external, and local imports_layout = "Vertical" # Vertical layout for readability # ============================================================================= # ๐Ÿ“‹ STANDARD IMPORT ORDER FOR ALL CRATES # ============================================================================= # # This order enforces the type governance hierarchy: # 1. Standard library (std::) # 2. External crates (serde, tokio, etc.) # 3. Prelude import (trading_engine::types::prelude::*) # 4. Configuration imports (config::*) # 5. Local crate imports # 6. Generated code imports (proto, etc.) # ============================================================================= # ๐Ÿ”’ TYPE GOVERNANCE FORMATTING RULES # ============================================================================= # Force prelude imports to be clearly visible reorder_imports = true # Automatic import reordering reorder_modules = true # Module order consistency merge_imports = false # Keep imports separate for clarity # Ensure wildcard imports (required for prelude) are formatted consistently use_small_heuristics = "Max" # Better formatting decisions # ============================================================================= # ๐Ÿ“ LINE LENGTH AND WRAPPING # ============================================================================= max_width = 100 # Consistent with HFT code standards hard_tabs = false # Use spaces for consistency tab_spaces = 4 # 4-space indentation # Import-specific line handling use_try_shorthand = true # Use ? operator imports_indent = "Block" # Indent wrapped imports merge_derives = true # Combine #[derive(...)] attributes # ============================================================================= # ๐Ÿงน CODE STRUCTURE FOR MAINTAINABILITY # ============================================================================= # Function and type formatting that supports type governance fn_args_layout = "Tall" # Vertical function arguments brace_style = "SameLineWhere" # Consistent brace placement where_single_line = true # Compact where clauses when possible # Struct and enum formatting (important for canonical types) struct_field_align_threshold = 20 # Align fields in structs enum_discrim_align_threshold = 20 # Align enum discriminants use_field_init_shorthand = true # Use shorthand field initialization # ============================================================================= # ๐Ÿ“ DOCUMENTATION AND COMMENTS # ============================================================================= # Ensure type governance documentation is preserved format_code_in_doc_comments = true # Format code examples wrap_comments = true # Wrap long comments comment_width = 80 # Comment line length normalize_comments = true # Consistent comment formatting normalize_doc_attributes = true # Consistent doc attributes # ============================================================================= # โšก HFT-SPECIFIC FORMATTING # ============================================================================= # Performance-critical code formatting single_line_if_else_max_width = 50 # Compact conditionals force_multiline_blocks = false # Allow compact blocks overflow_delimited_expr = true # Handle long expressions # Match expression formatting (common in trading logic) match_block_trailing_comma = true # Consistent comma usage match_arm_blocks = false # Compact match arms where possible newline_style = "Unix" # Consistent line endings # ============================================================================= # ๐ŸŽจ VISUAL ORGANIZATION # ============================================================================= # Make type governance violations more visible through formatting blank_lines_lower_bound = 0 # Minimum blank lines blank_lines_upper_bound = 2 # Maximum blank lines empty_item_single_line = false # No empty items on single line # Indent and alignment for complex types array_width = 60 # Array formatting threshold attr_fn_like_width = 70 # Attribute formatting chain_width = 60 # Method chain formatting fn_call_width = 60 # Function call formatting struct_lit_width = 18 # Struct literal formatting struct_variant_width = 35 # Enum struct variant formatting # ============================================================================= # ๐Ÿ”ง MACRO AND SPECIAL SYNTAX # ============================================================================= # Handle Rust macros (common in HFT for performance) format_macro_matchers = true # Format macro matchers format_macro_bodies = true # Format macro bodies macro_use_wildcards = false # Explicit macro imports # Generated code formatting (protobuf, etc.) format_generated_files = false # Don't format generated files skip_children = false # Format all Rust files # ============================================================================= # ๐Ÿšจ TYPE GOVERNANCE INTEGRATION # ============================================================================= # These settings specifically support type governance: # 1. Import grouping makes prelude imports clearly visible # 2. Consistent formatting helps identify duplicate type definitions # 3. Documentation formatting preserves governance comments # 4. Line length and structure support code review for violations # ============================================================================= # ๐ŸŽฏ VALIDATION AND ENFORCEMENT # ============================================================================= # Integration with type governance validation: # - CI runs `cargo fmt --check` to ensure consistent formatting # - Consistent imports make duplicate detection easier # - Clear structure supports code review for governance violations # ============================================================================= # ๐Ÿ—๏ธ EXAMPLES OF ENFORCED PATTERNS # ============================================================================= # # Standard service import pattern: # ```rust # use std::collections::HashMap; # use std::time::Duration; # # use serde::{Deserialize, Serialize}; # use tokio::sync::RwLock; # # use trading_engine::types::prelude::*; // CANONICAL TYPES # use config::*; // CONFIGURATION ONLY # # use crate::repository::OrderRepository; # use crate::service::OrderService; # ``` # # Test import pattern: # ```rust # use std::time::SystemTime; # # use trading_engine::types::prelude::*; // CANONICAL TYPES ONLY # # use crate::test_utils::*; # ```