Rust 2024 Zero-Cost Async Actor System & Lock-Free MPSC Architecture
Architect high-performance, memory-leak-proof concurrent actors in modern Rust 2024. Instructs AI to enforce RAII handles, typed enum protocols, and zero unsafe code blocks.
Parametric Customizer & Compiler Live Tool
Adjust the variables below. The prompt code and API payload update dynamically in real time.
Core stateful workload managed by the actor.
Protects against unbounded memory growth during spikes.
How the system responds to task panics and downstream errors.
Clean resource cleanup and drain logic.
You are a Principal Systems Architect and Rust Compiler Specialist authoring mission-critical distributed services in Rust 2024 edition. OBJECTIVE: Design and implement an asynchronous actor system in Rust 2024 for: Workload: High-frequency limit order book (matching engine with sub-microsecond price-time priority updates) Mailbox Strategy: Bounded tokio::sync::mpsc with try_send backpressure and drop telemetry alerts Error & Panic Policy: Supervisor tree that catches task panics via JoinHandle, logs root cause trace, and respawns clean actor state Shutdown Protocol: CancellationToken fan-out draining pending orders with a hard 10-second timeout guard STRICT RUST SAFETY & CODE QUALITY RULES: 1. 100% Safe Rust: Strictly `#![forbid(unsafe_code)]`; leverage ownership, RAII, and `tokio::sync::mpsc`. 2. Strongly-Typed Protocol: Actor messages MUST be modeled as non-exhaustive enums with `tokio::sync::oneshot::Sender<Result<T, ActorError>>` response channels for query patterns. 3. Zero Allocation Hot Path: Favor stack-allocated buffers and small-vector optimizations; avoid unnecessary `Arc<Mutex<T>>` wrapping where message passing suffices. 4. Clean Cancellation: Bind actor loops to `tokio_util::sync::CancellationToken` and drain remaining mailbox messages gracefully prior to process exit. 5. Production Error Handling: Utilize `thiserror` for library domain errors and return explicit `Result<(), ActorError>`.
Write zero-bug concurrent Rust systems at lightning speed with Cursor.
Leonardo Phoenix & Flux: Generate photorealistic studio assets with 150 daily free credits. Zero setup required.
πΈ Real Sample Outputs & Verified Results
Visual evidence and benchmark responses generated using this exact prompt formula.
π¬ Prompt Engineering Anatomy
Why this prompt consistently delivers high-tier results: technical parameter breakdown.
Actor Handle Pattern Separates the public `Clone`-able Handle containing an `mpsc::Sender` from the private actor loop containing state, ensuring zero shared mutable references.
Bounded Channel Backpressure Unbounded channels in high-throughput systems lead to unbounded heap growth and eventual OOM crash.
π¬ Frequently Asked Questions
Troubleshooting common edge cases, model incompatibilities, and best practices.
Does this work in Cursor AI and Windsurf?
Yes, this prompt generates idiomatic Rust compatible with modern Tokio 1.40+ and Rust 2021/2024 editions.
Why use message-passing actors instead of Mutex<OrderBook>?
Mutexes cause thread contention and lock starvation under high QPS. Actors process messages sequentially in a single task, completely eliminating lock overhead.
Cursor AI & Claude 3.5 Sonnet Pro Bundle
Supercharge your workflow with instant codebase indexing, multi-file edits, and automated system rules.
Explore Related AI Coding & Architecture Prompts View all β
Claude 3.5 Sonnet Senior Staff Full-Stack Refactoring Architect
Specialized prompt framework for Claude 3.5 Sonnet and Claude 3.7. Transforms messy legacy codebases into modular, testable, high-performance systems with automated regression tests.
cursorCursor AI (.cursorrules) for Next.js 15, React 19 & Tailwind CSS
Stops Cursor from writing outdated Next.js 13 patterns, Pages Router syntax, or deprecated React hooks. Enforces strict TypeScript, Server Actions, and modular clean architecture.
deepseekDeepSeek-R1 Autonomous Deep Research & Synthesis Engine
DeepSeek-R1 chain-of-thought framework designed to force deep reflection, counterfactual auditing, and hypothesis testing before producing production-ready research reports.