| name | ms-rust |
| description | ALWAYS use this skill BEFORE writing or modifying ANY Rust code (.rs files), even for simple Hello World programs. Enforces Microsoft Rust coding guidelines, applies M-CANONICAL-DOCS documentation, adds compliance comments, and validates against rust-guidelines.txt. This skill is MANDATORY for all Rust development. |
Rust Development
This skill automatically enforces Rust coding standards and best practices when creating or modifying Rust code.
Instructions
CRITICAL: This skill MUST be invoked for ANY Rust code operation, including:
- Creating new .rs files (even simple examples like Hello World)
- Modifying existing .rs files (any change, no matter how small)
- Reviewing Rust code
- Refactoring Rust code
Process:
- Read the rust-guidelines.txt to understand all compliance requirements
- Before writing/modifying ANY Rust code, ensure edits are conformant to the guidelines
- Apply proper M-CANONICAL-DOCS documentation format
- Add compliance comments
- Comments must ALWAYS be written in American English, unless the user explicitly requests 'write comments in French' or provides another clear instruction specifying a different comment language.
- If the file is fully compliant, add a comment:
// Rust guideline compliant {date}where {date} is the guideline date/version
Key Guidelines to Apply:
Documentation (M-CANONICAL-DOCS)
/// Summary sentence < 15 words.
///
/// Extended documentation in free form.
///
/// # Examples
/// One or more examples that show API usage.
///
/// # Errors
/// If fn returns `Result`, list known error conditions
///
/// # Panics
/// If fn may panic, list when this may happen
///
/// # Safety
/// If fn is `unsafe`, list all conditions a caller must uphold.
pub fn foo() {}
Error Handling (M-ERRORS-CANONICAL-STRUCTS)
- Use
anyhoworeyrefor applications - Use custom error structs with
Backtracefor libraries - Implement
Debug,Display, andstd::error::Error
Performance (M-MIMALLOC-APPS)
- Applications should use
mimallocas global allocator
Types (M-PUBLIC-DEBUG)
- All public types must implement
Debug - Sensitive types need custom
Debugimplementation
Safety (M-UNSOUND)
- No unsound code ever
unsafeonly for UB risk scenarios- Document all safety requirements
Services (M-SERVICES-CLONE)
- Use
Arc<Inner>pattern for heavyweight services - Implement
Clonefor shared ownership
No exceptions: Even for trivial code like "Hello World", guidelines must be followed.