| name | moai-lang-rust |
| description | Rust 1.92+ development specialist covering Axum, Tokio, SQLx, and memory-safe systems programming. Use when building high-performance, memory-safe applications or WebAssembly.
|
| license | Apache-2.0 |
| compatibility | Designed for Claude Code |
| allowed-tools | Read Grep Glob mcp__context7__resolve-library-id mcp__context7__get-library-docs |
| user-invocable | false |
| metadata | {"version":"1.2.0","category":"language","status":"active","updated":"2026-01-11","modularized":"false","tags":"language, rust, axum, tokio, sqlx, serde, wasm, cargo"} |
| progressive_disclosure | {"enabled":true,"level1_tokens":100,"level2_tokens":5000} |
| triggers | {"keywords":["Rust","Axum","Tokio","SQLx","serde",".rs","Cargo.toml","async","await","lifetime","trait","ownership","borrowing","performance","optimization","clippy","memory safety"],"languages":["rust"]} |
Quick Reference (30 seconds)
Rust 1.92+ Development Specialist with deep patterns for high-performance, memory-safe applications.
Auto-Triggers: .rs, Cargo.toml, async/await, Tokio, Axum, SQLx, serde, lifetimes, traits
Core Use Cases:
- High-performance REST APIs and microservices
- Memory-safe concurrent systems
- CLI tools and system utilities
- WebAssembly applications
- Low-latency networking services
Quick Patterns:
Axum REST API: Create Router with route macro chaining path and handler. Add with_state for shared state. Bind TcpListener with tokio::net and serve with axum::serve.
Async Handler with SQLx: Define async handler function taking State extractor for AppState and Path extractor for id. Use sqlx::query_as! macro with SQL string and bind parameters. Call fetch_optional on pool, await, and use ok_or for error conversion. Return Json wrapped result.
Implementation Guide (5 minutes)
Rust 1.92 Features
Modern Rust Features:
- Rust 2024 Edition available (released with Rust 1.85)
- Async traits in stable (no more async-trait crate needed)
- Const generics for compile-time array sizing
- let-else for pattern matching with early return
- Improved borrow checker with polonius
Async Traits (Stable): Define trait with async fn signatures. Implement trait for concrete types with async fn implementations. Call sqlx macros directly in trait methods.
Let-Else Pattern: Use let Some(value) = option else with return for early exit. Chain multiple let-else statements for sequential validation. Return error types in else blocks.
Web Framework: Axum 0.8
Installation: In Cargo.toml dependencies section, add axum version 0.8, tokio version 1.48 with full features, and tower-http version 0.6 with cors and trace features.
Complete API Setup: Import extractors from axum::extract and routing macros. Define Clone-derive AppState struct holding PgPool. In tokio::main async main, create pool with PgPoolOptions setting max_connections and connecting with DATABASE_URL from env. Build Router with route chains for paths and handlers, add CorsLayer, and call with_state. Bind TcpListener and call axum::serve.
Handler Patterns: Define async handlers taking State, Path, and Query extractors with appropriate types. Use sqlx::query_as! for type-safe queries with positional binds. Return Result with Json success and AppError failure.
Async Runtime: Tokio 1.48
Task Spawning and Channels: Create mpsc channel with capacity. Spawn worker tasks with tokio::spawn that receive from channel in loop. For timeouts, use tokio::select! macro with operation branch and sleep branch, returning error on timeout.