Rust Code Implementation and Debugging
Get Rust code and targeted fixes for ownership, lifetimes, traits, Tokio concurrency, errors, and unsafe boundaries.
Before & after
Same prompt, same agent — the only difference is the skill.
Rust's async/await and tokio runtime are great for handling concurrent requests. You'll want to think about ownership and lifetimes — making sure your references live long enough for the async operations. Connection pooling is critical for database performance, so you might want to use a library like sqlx with a connection pool. You could spawn tasks with tokio::spawn to handle multiple requests concurrently. Error handling gets trickier with async — you'll want to make sure errors propagate correctly. Do you have the current code I can look at? Understanding the data structures and error types will help me suggest the right async patterns.
REFACTORING PLAN
CURRENT BOTTLENECK
• Sequential database queries in loop
• New connection per request = 100ms overhead × 10 requests = 1000ms total
• Single-threaded execution blocks on I/O
ASYNC PATTERN: tokio with connection pool
1. Initialize connection pool at startup:
let pool = sqlx::PgPool::connect(db_url).await?;
pool.set_max_connections(20); // Match DB max_connections / threads
2. Spawn concurrent tasks:
let handles: Vec<_> = requests.iter()
.map(|req| {
let pool = pool.clone(); // Arc handle, no move
tokio::spawn(async move { query_db(&pool, req).await })
}).collect();
3. Await all in parallel:
let results = futures::future::try_join_all(handles).await?;
OWNERSHIP STRATEGY
→ Pool is Arc, cloning is cheap (reference count increment)
→ Request data is moved into spawned tasks (no shared mutable state)
→ Lifetime: async fn does not need explicit lifetimes if no borrowed references cross await
→ Error handling: .map_err() converts per-task errors, then collect() in parent
RESULT
Old: 1000ms for 10 queries
New: 100ms for 10 queries (limited by single slowest query + pool overhead)
Scaling: Pool size 20, 10 concurrent tasks = 2 batches through queue
TEST STRATEGY
• Unit: Mock database returns in 50ms
• Integration: Real DB, measure latency distribution
• Load: Drive 50 concurrent requests, track p95 latency and error rateAbout this skill
“The borrow checker keeps rejecting this” often points to an ownership decision hidden in the API. This skill produces working Rust designs and targeted patches by tracing who owns each value, how long references remain valid, and what happens when concurrent work fails or gets canceled.
What it does
- Diagnoses ownership and lifetime errors from the relevant signatures, compiler output, and call sites, then proposes the smallest correct fix.
- Designs borrowed and owned APIs without reflexively adding clones, lifetime parameters, or shared locks.
- Implements Tokio concurrency with explicit task ownership, bounded work, cancellation behavior, and shutdown handling.
- Chooses concrete types, generics, and trait objects based on actual extension and dispatch needs.
- Builds recoverable error paths and reviews unsafe or FFI code against explicit validity requirements.
- Separates measured performance findings from hypotheses and supplies focused verification commands.
What you get
A scoped implementation, patch, or severity-ranked review with the ownership reasoning, relevant tradeoffs, and verification status. Larger implementations include necessary imports, dependency changes, and tests for meaningful failure paths; small questions get a direct answer.
Best for
Rust application and library developers dealing with compiler errors, public API design, async services, systems interfaces, or performance-sensitive code.
SKILL.md preview
---
name: rust-code-implementation-and-debugging
description: >-
Implements, reviews, and debugs Rust by tracing ownership and lifetime contracts, selecting trait boundaries, and checking async cancellation and unsafe invariants. Use when the user says "fix this borrow checker error", "my reference does not live long enough", "write this in Rust", "review this Rust API", "my Tokio task won't spawn", "this async code keeps hanging", "make this Rust code faster", or "check this unsafe FFI boundary".
---
# Rust Code Implementation and Debugging
… (sign up to view the full skill)More development skills
View all Development skills →SQL Query Optimization and Schema Review
Get SQL rewrites, evidence-based index recommendations, schema reviews, and dialect migrations with validation steps.
C# API and Blazor Implementation
Build and fix C# APIs and Blazor components with safe EF Core queries, cancellation, and focused tests.
Type-Safe PHP Applications and APIs
Build and repair typed PHP applications with Laravel or Symfony, safe database changes, and targeted tests.
Modern C++ Implementation, Debugging & Optimization
Build and repair modern C++ with explicit ownership, constrained templates, race analysis, profiling, and target-based CMake.