Add Copilot instruction file for Rust (#154)
* add instructions for rust * update readme
This commit is contained in:
parent
adfebcd06b
commit
dfa345f89b
@ -70,6 +70,7 @@ Team and project-specific instructions to enhance GitHub Copilot's behavior for
|
|||||||
| [Quarkus](instructions/quarkus.instructions.md) | Quarkus development standards and instructions | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fquarkus.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fquarkus.instructions.md) |
|
| [Quarkus](instructions/quarkus.instructions.md) | Quarkus development standards and instructions | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fquarkus.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fquarkus.instructions.md) |
|
||||||
| [ReactJS Development Instructions](instructions/reactjs.instructions.md) | ReactJS development standards and best practices | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Freactjs.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Freactjs.instructions.md) |
|
| [ReactJS Development Instructions](instructions/reactjs.instructions.md) | ReactJS development standards and best practices | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Freactjs.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Freactjs.instructions.md) |
|
||||||
| [Ruby on Rails](instructions/ruby-on-rails.instructions.md) | Ruby on Rails coding conventions and guidelines | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fruby-on-rails.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fruby-on-rails.instructions.md) |
|
| [Ruby on Rails](instructions/ruby-on-rails.instructions.md) | Ruby on Rails coding conventions and guidelines | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fruby-on-rails.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fruby-on-rails.instructions.md) |
|
||||||
|
| [Rust Coding Conventions and Best Practices](instructions/rust.instructions.md) | Rust programming language coding conventions and best practices | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Frust.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Frust.instructions.md) |
|
||||||
| [Secure Coding and OWASP Guidelines](instructions/security-and-owasp.instructions.md) | Comprehensive secure coding instructions for all languages and frameworks, based on OWASP Top 10 and industry best practices. | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fsecurity-and-owasp.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fsecurity-and-owasp.instructions.md) |
|
| [Secure Coding and OWASP Guidelines](instructions/security-and-owasp.instructions.md) | Comprehensive secure coding instructions for all languages and frameworks, based on OWASP Top 10 and industry best practices. | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fsecurity-and-owasp.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fsecurity-and-owasp.instructions.md) |
|
||||||
| [Self-explanatory Code Commenting Instructions](instructions/self-explanatory-code-commenting.instructions.md) | Guidelines for GitHub Copilot to write comments to achieve self-explanatory code with less comments. Examples are in JavaScript but it should work on any language that has comments. | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fself-explanatory-code-commenting.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fself-explanatory-code-commenting.instructions.md) |
|
| [Self-explanatory Code Commenting Instructions](instructions/self-explanatory-code-commenting.instructions.md) | Guidelines for GitHub Copilot to write comments to achieve self-explanatory code with less comments. Examples are in JavaScript but it should work on any language that has comments. | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fself-explanatory-code-commenting.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fself-explanatory-code-commenting.instructions.md) |
|
||||||
| [Spec Driven Workflow v1](instructions/spec-driven-workflow-v1.instructions.md) | Specification-Driven Workflow v1 provides a structured approach to software development, ensuring that requirements are clearly defined, designs are meticulously planned, and implementations are thoroughly documented and validated. | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fspec-driven-workflow-v1.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fspec-driven-workflow-v1.instructions.md) |
|
| [Spec Driven Workflow v1](instructions/spec-driven-workflow-v1.instructions.md) | Specification-Driven Workflow v1 provides a structured approach to software development, ensuring that requirements are clearly defined, designs are meticulously planned, and implementations are thoroughly documented and validated. | [](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fspec-driven-workflow-v1.instructions.md) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fspec-driven-workflow-v1.instructions.md) |
|
||||||
|
|||||||
135
instructions/rust.instructions.md
Normal file
135
instructions/rust.instructions.md
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
---
|
||||||
|
description: 'Rust programming language coding conventions and best practices'
|
||||||
|
applyTo: '**/*.rs'
|
||||||
|
---
|
||||||
|
|
||||||
|
# Rust Coding Conventions and Best Practices
|
||||||
|
|
||||||
|
Follow idiomatic Rust practices and community standards when writing Rust code.
|
||||||
|
|
||||||
|
These instructions are based on [The Rust Book](https://doc.rust-lang.org/book/), [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/), [RFC 430 naming conventions](https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md), and the broader Rust community at [users.rust-lang.org](https://users.rust-lang.org).
|
||||||
|
|
||||||
|
## General Instructions
|
||||||
|
|
||||||
|
- Always prioritize readability, safety, and maintainability.
|
||||||
|
- Use strong typing and leverage Rust's ownership system for memory safety.
|
||||||
|
- Break down complex functions into smaller, more manageable functions.
|
||||||
|
- For algorithm-related code, include explanations of the approach used.
|
||||||
|
- Write code with good maintainability practices, including comments on why certain design decisions were made.
|
||||||
|
- Handle errors gracefully using `Result<T, E>` and provide meaningful error messages.
|
||||||
|
- For external dependencies, mention their usage and purpose in documentation.
|
||||||
|
- Use consistent naming conventions following [RFC 430](https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md).
|
||||||
|
- Write idiomatic, safe, and efficient Rust code that follows the borrow checker's rules.
|
||||||
|
- Ensure code compiles without warnings.
|
||||||
|
|
||||||
|
## Patterns to Follow
|
||||||
|
|
||||||
|
- Use modules (`mod`) and public interfaces (`pub`) to encapsulate logic.
|
||||||
|
- Handle errors properly using `?`, `match`, or `if let`.
|
||||||
|
- Use `serde` for serialization and `thiserror` or `anyhow` for custom errors.
|
||||||
|
- Implement traits to abstract services or external dependencies.
|
||||||
|
- Structure async code using `async/await` and `tokio` or `async-std`.
|
||||||
|
- Prefer enums over flags and states for type safety.
|
||||||
|
- Use builders for complex object creation.
|
||||||
|
- Split binary and library code (`main.rs` vs `lib.rs`) for testability and reuse.
|
||||||
|
- Use `rayon` for data parallelism and CPU-bound tasks.
|
||||||
|
- Use iterators instead of index-based loops as they're often faster and safer.
|
||||||
|
- Use `&str` instead of `String` for function parameters when you don't need ownership.
|
||||||
|
- Prefer borrowing and zero-copy operations to avoid unnecessary allocations.
|
||||||
|
|
||||||
|
### Ownership, Borrowing, and Lifetimes
|
||||||
|
|
||||||
|
- Prefer borrowing (`&T`) over cloning unless ownership transfer is necessary.
|
||||||
|
- Use `&mut T` when you need to modify borrowed data.
|
||||||
|
- Explicitly annotate lifetimes when the compiler cannot infer them.
|
||||||
|
- Use `Rc<T>` for single-threaded reference counting and `Arc<T>` for thread-safe reference counting.
|
||||||
|
- Use `RefCell<T>` for interior mutability in single-threaded contexts and `Mutex<T>` or `RwLock<T>` for multi-threaded contexts.
|
||||||
|
|
||||||
|
## Patterns to Avoid
|
||||||
|
|
||||||
|
- Don't use `unwrap()` or `expect()` unless absolutely necessary—prefer proper error handling.
|
||||||
|
- Avoid panics in library code—return `Result` instead.
|
||||||
|
- Don't rely on global mutable state—use dependency injection or thread-safe containers.
|
||||||
|
- Avoid deeply nested logic—refactor with functions or combinators.
|
||||||
|
- Don't ignore warnings—treat them as errors during CI.
|
||||||
|
- Avoid `unsafe` unless required and fully documented.
|
||||||
|
- Don't overuse `clone()`, use borrowing instead of cloning unless ownership transfer is needed.
|
||||||
|
- Avoid premature `collect()`, keep iterators lazy until you actually need the collection.
|
||||||
|
- Avoid unnecessary allocations—prefer borrowing and zero-copy operations.
|
||||||
|
|
||||||
|
## Code Style and Formatting
|
||||||
|
|
||||||
|
- Follow the Rust Style Guide and use `rustfmt` for automatic formatting.
|
||||||
|
- Keep lines under 100 characters when possible.
|
||||||
|
- Place function and struct documentation immediately before the item using `///`.
|
||||||
|
- Use `cargo clippy` to catch common mistakes and enforce best practices.
|
||||||
|
|
||||||
|
## Error Handling
|
||||||
|
|
||||||
|
- Use `Result<T, E>` for recoverable errors and `panic!` only for unrecoverable errors.
|
||||||
|
- Prefer `?` operator over `unwrap()` or `expect()` for error propagation.
|
||||||
|
- Create custom error types using `thiserror` or implement `std::error::Error`.
|
||||||
|
- Use `Option<T>` for values that may or may not exist.
|
||||||
|
- Provide meaningful error messages and context.
|
||||||
|
- Error types should be meaningful and well-behaved (implement standard traits).
|
||||||
|
- Validate function arguments and return appropriate errors for invalid input.
|
||||||
|
|
||||||
|
## API Design Guidelines
|
||||||
|
|
||||||
|
### Common Traits Implementation
|
||||||
|
Eagerly implement common traits where appropriate:
|
||||||
|
- `Copy`, `Clone`, `Eq`, `PartialEq`, `Ord`, `PartialOrd`, `Hash`, `Debug`, `Display`, `Default`
|
||||||
|
- Use standard conversion traits: `From`, `AsRef`, `AsMut`
|
||||||
|
- Collections should implement `FromIterator` and `Extend`
|
||||||
|
- Note: `Send` and `Sync` are auto-implemented by the compiler when safe; avoid manual implementation unless using `unsafe` code
|
||||||
|
|
||||||
|
### Type Safety and Predictability
|
||||||
|
- Use newtypes to provide static distinctions
|
||||||
|
- Arguments should convey meaning through types; prefer specific types over generic `bool` parameters
|
||||||
|
- Use `Option<T>` appropriately for truly optional values
|
||||||
|
- Functions with a clear receiver should be methods
|
||||||
|
- Only smart pointers should implement `Deref` and `DerefMut`
|
||||||
|
|
||||||
|
### Future Proofing
|
||||||
|
- Use sealed traits to protect against downstream implementations
|
||||||
|
- Structs should have private fields
|
||||||
|
- Functions should validate their arguments
|
||||||
|
- All public types must implement `Debug`
|
||||||
|
|
||||||
|
## Testing and Documentation
|
||||||
|
|
||||||
|
- Write comprehensive unit tests using `#[cfg(test)]` modules and `#[test]` annotations.
|
||||||
|
- Use test modules alongside the code they test (`mod tests { ... }`).
|
||||||
|
- Write integration tests in `tests/` directory with descriptive filenames.
|
||||||
|
- Write clear and concise comments for each function, struct, enum, and complex logic.
|
||||||
|
- Ensure functions have descriptive names and include comprehensive documentation.
|
||||||
|
- Document all public APIs with rustdoc (`///` comments) following the [API Guidelines](https://rust-lang.github.io/api-guidelines/).
|
||||||
|
- Use `#[doc(hidden)]` to hide implementation details from public documentation.
|
||||||
|
- Document error conditions, panic scenarios, and safety considerations.
|
||||||
|
- Examples should use `?` operator, not `unwrap()` or deprecated `try!` macro.
|
||||||
|
|
||||||
|
## Project Organization
|
||||||
|
|
||||||
|
- Use semantic versioning in `Cargo.toml`.
|
||||||
|
- Include comprehensive metadata: `description`, `license`, `repository`, `keywords`, `categories`.
|
||||||
|
- Use feature flags for optional functionality.
|
||||||
|
- Organize code into modules using `mod.rs` or named files.
|
||||||
|
- Keep `main.rs` or `lib.rs` minimal - move logic to modules.
|
||||||
|
|
||||||
|
## Quality Checklist
|
||||||
|
|
||||||
|
Before publishing or reviewing Rust code, ensure:
|
||||||
|
|
||||||
|
### Core Requirements
|
||||||
|
- [ ] **Naming**: Follows RFC 430 naming conventions
|
||||||
|
- [ ] **Traits**: Implements `Debug`, `Clone`, `PartialEq` where appropriate
|
||||||
|
- [ ] **Error Handling**: Uses `Result<T, E>` and provides meaningful error types
|
||||||
|
- [ ] **Documentation**: All public items have rustdoc comments with examples
|
||||||
|
- [ ] **Testing**: Comprehensive test coverage including edge cases
|
||||||
|
|
||||||
|
### Safety and Quality
|
||||||
|
- [ ] **Safety**: No unnecessary `unsafe` code, proper error handling
|
||||||
|
- [ ] **Performance**: Efficient use of iterators, minimal allocations
|
||||||
|
- [ ] **API Design**: Functions are predictable, flexible, and type-safe
|
||||||
|
- [ ] **Future Proofing**: Private fields in structs, sealed traits where appropriate
|
||||||
|
- [ ] **Tooling**: Code passes `cargo fmt`, `cargo clippy`, and `cargo test`
|
||||||
Loading…
x
Reference in New Issue
Block a user