Always prioritize memory safety. Explain ownership, borrowing, and lifetimes in code suggestions.
Use unsafe blocks only when absolutely necessary and document safety invariants thoroughly.
Consider performance implications of all code suggestions. Prefer zero-cost abstractions,
minimize heap allocations, and use iterators over manual loops when appropriate.
Suggest Vec::with_capacity() for known sizes.
Follow Rust idioms: use Result<T, E> and Option<T> instead of exceptions/null,
leverage pattern matching, implement common traits (Debug, Clone, PartialEq),
follow naming conventions (snake_case for functions, PascalCase for types).
Use the ? operator for error propagation, create custom error types implementing std::error::Error,
provide meaningful error messages with context. Suggest thiserror or anyhow crates when appropriate.
Write comprehensive unit tests with #[cfg(test)], include property-based testing suggestions,
document public APIs with /// comments including examples that compile with cargo test.
For async code, understand Future trait and async runtimes (tokio, async-std),
avoid blocking in async contexts, consider Stream for async iteration,
handle cancellation and timeouts appropriately.
Format this Rust code according to rustfmt standards. Ensure proper indentation,
spacing, line breaks, and Rust community style conventions. Explain any significant
formatting changes made and why they improve readability.
Analyze this Rust code as if running `cargo clippy` and provide suggestions for:
1. Performance improvements and optimization opportunities
2. Idiomatic Rust patterns and best practices
3. Potential bugs, logic errors, or edge cases
4. Memory usage optimizations and allocation patterns
5. Code style improvements and readability enhancements
Provide specific, actionable recommendations with explanations.
Generate comprehensive unit tests for this Rust code including:
1. Happy path tests covering normal operation
2. Edge cases and boundary conditions
3. Error cases and failure scenarios
4. Property-based tests where appropriate using proptest
5. Integration tests if needed
Use proper Rust testing conventions with #[cfg(test)], assert! macros,
and Result<(), Box<dyn std::error::Error>> for fallible tests.
Create performance benchmarks for this Rust code using criterion.rs:
1. Benchmark setup and teardown procedures
2. Multiple input sizes for complexity analysis
3. Comparison with alternative implementations
4. Memory usage analysis where relevant
5. Statistical measurement and confidence intervals
Provide complete benchmark code and explain expected performance characteristics.
Review any unsafe code blocks in this Rust code for:
1. Safety invariants and their proper documentation
2. Necessity of unsafe usage and safe alternatives
3. Proper encapsulation of unsafe operations
4. Memory safety guarantees and potential violations
5. Thread safety considerations in concurrent contexts
Provide detailed analysis and suggest safer alternatives where possible.
Improve error handling in this Rust code by:
1. Converting panics to proper Result types
2. Creating custom error types with thiserror
3. Adding proper error context and error chains
4. Using the ? operator effectively for propagation
5. Implementing Display and Debug for better debugging
Provide improved code with comprehensive error handling.
Convert this synchronous Rust code to async/await patterns:
1. Identify I/O-bound operations for async conversion
2. Add appropriate async runtime setup (tokio recommended)
3. Handle concurrent operations with join!/select!/spawn
4. Manage async error propagation properly
5. Consider cancellation, timeouts, and graceful shutdown
Explain benefits, trade-offs, and when async is appropriate.
Analyze this Rust code for performance optimization:
1. Memory allocation patterns and heap vs stack usage
2. Iterator chains vs manual loops efficiency
3. Clone usage vs borrowing and reference patterns
4. Algorithm complexity analysis (time and space)
5. Cache efficiency and memory layout considerations
6. Potential for parallelization with rayon
Provide specific, measurable improvements with before/after analysis.
No Data configured
No MCP Servers configured