From 08d7d4e24f85a2cac7bfa6dacde0f695f168f34b Mon Sep 17 00:00:00 2001 From: James Muriuki Date: Mon, 23 Mar 2026 17:45:56 +0000 Subject: [PATCH 1/2] Add symposium-rust-lang skill --- skills/symposium-rust-lang/SKILL.md | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 skills/symposium-rust-lang/SKILL.md diff --git a/skills/symposium-rust-lang/SKILL.md b/skills/symposium-rust-lang/SKILL.md new file mode 100644 index 0000000..27f2b00 --- /dev/null +++ b/skills/symposium-rust-lang/SKILL.md @@ -0,0 +1,59 @@ +You are an expert in Rust, async programming, and concurrent systems. + +Key Principles +- Write clear, concise, and idiomatic Rust code with accurate examples. +- Use async programming paradigms effectively, leveraging `tokio` for concurrency. +- Prioritize modularity, clean code organization, and efficient resource management. +- Use expressive variable names that convey intent (e.g., `is_ready`, `has_data`). +- Adhere to Rust's naming conventions: snake_case for variables and functions, PascalCase for types and structs. +- Avoid code duplication; use functions and modules to encapsulate reusable logic. +- Write code with safety, concurrency, and performance in mind, embracing Rust's ownership and type system. + +Async Programming +- Use `tokio` as the async runtime for handling asynchronous tasks and I/O. +- Implement async functions using `async fn` syntax. +- Leverage `tokio::spawn` for task spawning and concurrency. +- Use `tokio::select!` for managing multiple async tasks and cancellations. +- Favor structured concurrency: prefer scoped tasks and clean cancellation paths. +- Implement timeouts, retries, and backoff strategies for robust async operations. + +Channels and Concurrency +- Use Rust's `tokio::sync::mpsc` for asynchronous, multi-producer, single-consumer channels. +- Use `tokio::sync::broadcast` for broadcasting messages to multiple consumers. +- Implement `tokio::sync::oneshot` for one-time communication between tasks. +- Prefer bounded channels for backpressure; handle capacity limits gracefully. +- Use `tokio::sync::Mutex` and `tokio::sync::RwLock` for shared state across tasks, avoiding deadlocks. + +Error Handling and Safety +- Embrace Rust's Result and Option types for error handling. +- Use `?` operator to propagate errors in async functions. +- Implement custom error types using `thiserror` or `anyhow` for more descriptive errors. +- Handle errors and edge cases early, returning errors where appropriate. +- Use `.await` responsibly, ensuring safe points for context switching. + +Testing +- Write unit tests with `tokio::test` for async tests. +- Use `tokio::time::pause` for testing time-dependent code without real delays. +- Implement integration tests to validate async behavior and concurrency. +- Use mocks and fakes for external dependencies in tests. + +Performance Optimization +- Minimize async overhead; use sync code where async is not needed. +- Avoid blocking operations inside async functions; offload to dedicated blocking threads if necessary. +- Use `tokio::task::yield_now` to yield control in cooperative multitasking scenarios. +- Optimize data structures and algorithms for async use, reducing contention and lock duration. +- Use `tokio::time::sleep` and `tokio::time::interval` for efficient time-based operations. + +Key Conventions +1. Structure the application into modules: separate concerns like networking, database, and business logic. +2. Use environment variables for configuration management (e.g., `dotenv` crate). +3. Ensure code is well-documented with inline comments and Rustdoc. + +Async Ecosystem +- Use `tokio` for async runtime and task management. +- Leverage `hyper` or `reqwest` for async HTTP requests. +- Use `serde` for serialization/deserialization. +- Use `sqlx` or `tokio-postgres` for async database interactions. +- Utilize `tonic` for gRPC with async support. + +Refer to Rust's async book and `tokio` documentation for in-depth information on async patterns, best practices, and advanced features. \ No newline at end of file From 1bc026d67a5b156eff61f6179626718d3d42fc38 Mon Sep 17 00:00:00 2001 From: James Muriuki Date: Mon, 23 Mar 2026 21:14:15 +0300 Subject: [PATCH 2/2] Update Rust skill guidelines and conventions --- skills/symposium-rust-lang/SKILL.md | 153 +++++++++++++++++----------- 1 file changed, 94 insertions(+), 59 deletions(-) diff --git a/skills/symposium-rust-lang/SKILL.md b/skills/symposium-rust-lang/SKILL.md index 27f2b00..8781e1d 100644 --- a/skills/symposium-rust-lang/SKILL.md +++ b/skills/symposium-rust-lang/SKILL.md @@ -1,59 +1,94 @@ -You are an expert in Rust, async programming, and concurrent systems. - -Key Principles -- Write clear, concise, and idiomatic Rust code with accurate examples. -- Use async programming paradigms effectively, leveraging `tokio` for concurrency. -- Prioritize modularity, clean code organization, and efficient resource management. -- Use expressive variable names that convey intent (e.g., `is_ready`, `has_data`). -- Adhere to Rust's naming conventions: snake_case for variables and functions, PascalCase for types and structs. -- Avoid code duplication; use functions and modules to encapsulate reusable logic. -- Write code with safety, concurrency, and performance in mind, embracing Rust's ownership and type system. - -Async Programming -- Use `tokio` as the async runtime for handling asynchronous tasks and I/O. -- Implement async functions using `async fn` syntax. -- Leverage `tokio::spawn` for task spawning and concurrency. -- Use `tokio::select!` for managing multiple async tasks and cancellations. -- Favor structured concurrency: prefer scoped tasks and clean cancellation paths. -- Implement timeouts, retries, and backoff strategies for robust async operations. - -Channels and Concurrency -- Use Rust's `tokio::sync::mpsc` for asynchronous, multi-producer, single-consumer channels. -- Use `tokio::sync::broadcast` for broadcasting messages to multiple consumers. -- Implement `tokio::sync::oneshot` for one-time communication between tasks. -- Prefer bounded channels for backpressure; handle capacity limits gracefully. -- Use `tokio::sync::Mutex` and `tokio::sync::RwLock` for shared state across tasks, avoiding deadlocks. - -Error Handling and Safety -- Embrace Rust's Result and Option types for error handling. -- Use `?` operator to propagate errors in async functions. -- Implement custom error types using `thiserror` or `anyhow` for more descriptive errors. -- Handle errors and edge cases early, returning errors where appropriate. -- Use `.await` responsibly, ensuring safe points for context switching. - -Testing -- Write unit tests with `tokio::test` for async tests. -- Use `tokio::time::pause` for testing time-dependent code without real delays. -- Implement integration tests to validate async behavior and concurrency. -- Use mocks and fakes for external dependencies in tests. - -Performance Optimization -- Minimize async overhead; use sync code where async is not needed. -- Avoid blocking operations inside async functions; offload to dedicated blocking threads if necessary. -- Use `tokio::task::yield_now` to yield control in cooperative multitasking scenarios. -- Optimize data structures and algorithms for async use, reducing contention and lock duration. -- Use `tokio::time::sleep` and `tokio::time::interval` for efficient time-based operations. - -Key Conventions -1. Structure the application into modules: separate concerns like networking, database, and business logic. -2. Use environment variables for configuration management (e.g., `dotenv` crate). -3. Ensure code is well-documented with inline comments and Rustdoc. - -Async Ecosystem -- Use `tokio` for async runtime and task management. -- Leverage `hyper` or `reqwest` for async HTTP requests. -- Use `serde` for serialization/deserialization. -- Use `sqlx` or `tokio-postgres` for async database interactions. -- Utilize `tonic` for gRPC with async support. - -Refer to Rust's async book and `tokio` documentation for in-depth information on async patterns, best practices, and advanced features. \ No newline at end of file +--- +name: symposium-rust-lang +description: "Use when asking about Rust code style or best practices. Keywords: naming, formatting, comment, clippy, rustfmt, lint, code style, best practice, P.NAM, G.FMT, code review, naming convention, variable naming, function naming, type naming. +user-invocable: false +--- + +# Rust Coding Guidelines (50 Core Rules) + +## Naming (Rust-Specific) + +| Rule | Guideline | +|------|-----------| +| No `get_` prefix | `fn name()` not `fn get_name()` | +| Iterator convention | `iter()` / `iter_mut()` / `into_iter()` | +| Conversion naming | `as_` (cheap &), `to_` (expensive), `into_` (ownership) | +| Static var prefix | `G_CONFIG` for `static`, no prefix for `const` | + +## Data Types + +| Rule | Guideline | +|------|-----------| +| Use newtypes | `struct Email(String)` for domain semantics | +| Prefer slice patterns | `if let [first, .., last] = slice` | +| Pre-allocate | `Vec::with_capacity()`, `String::with_capacity()` | +| Avoid Vec abuse | Use arrays for fixed sizes | + +## Strings + +| Rule | Guideline | +|------|-----------| +| Prefer bytes | `s.bytes()` over `s.chars()` when ASCII | +| Use `Cow` | When might modify borrowed data | +| Use `format!` | Over string concatenation with `+` | +| Avoid nested iteration | `contains()` on string is O(n*m) | + +## Error Handling + +| Rule | Guideline | +|------|-----------| +| Use `?` propagation | Not `try!()` macro | +| `expect()` over `unwrap()` | When value guaranteed | +| Assertions for invariants | `assert!` at function entry | + +## Memory + +| Rule | Guideline | +|------|-----------| +| Meaningful lifetimes | `'src`, `'ctx` not just `'a` | +| `try_borrow()` for RefCell | Avoid panic | +| Shadowing for transformation | `let x = x.parse()?` | + +## Concurrency + +| Rule | Guideline | +|------|-----------| +| Identify lock ordering | Prevent deadlocks | +| Atomics for primitives | Not Mutex for bool/usize | +| Choose memory order carefully | Relaxed/Acquire/Release/SeqCst | + +## Async + +| Rule | Guideline | +|------|-----------| +| Sync for CPU-bound | Async is for I/O | +| Don't hold locks across await | Use scoped guards | + +## Macros + +| Rule | Guideline | +|------|-----------| +| Avoid unless necessary | Prefer functions/generics | +| Follow Rust syntax | Macro input should look like Rust | + +## Deprecated → Better + +| Deprecated | Better | Since | +|------------|--------|-------| +| `lazy_static!` | `std::sync::OnceLock` | 1.70 | +| `once_cell::Lazy` | `std::sync::LazyLock` | 1.80 | +| `std::sync::mpsc` | `crossbeam::channel` | - | +| `std::sync::Mutex` | `parking_lot::Mutex` | - | +| `failure`/`error-chain` | `thiserror`/`anyhow` | - | +| `try!()` | `?` operator | 2018 | + +## Quick Reference + +``` +Naming: snake_case (fn/var), CamelCase (type), SCREAMING_CASE (const) +Format: rustfmt (just use it) +Docs: /// for public items, //! for module docs +Lint: #![warn(clippy::all)] +``` + +Claude knows Rust conventions well. These are the non-obvious Rust-specific rules.