rust

rust is a cursor rule for Cursor from PostHog/posthog-foss. It costs 903 tokens per session, scanned A, original, MIT.

Coding rules for Rust services, with guidance for asynchronous and concurrent programming using Tokio. Rust is a programming language designed for fast software with strong memory-safety checks.

In plain words
What is it for?
Use them when writing or reviewing Rust service code, especially asynchronous functions, task spawning, and concurrent operations.
Why use it?
They provide project-specific conventions for organizing Rust code and handling multiple tasks safely and efficiently.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/posthog/posthog-foss/rust
Clone the repo
git clone --depth 1 https://github.com/PostHog/posthog-foss

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rust

README.md
[![agentmods](https://agentmods.dev/badge/rules/posthog/posthog-foss/rust.svg)](https://agentmods.dev/rules/posthog/posthog-foss/rust)
Your own site
<a href="https://agentmods.dev/rules/posthog/posthog-foss/rust"><img src="https://agentmods.dev/badge/rules/posthog/posthog-foss/rust.svg" alt="Measured on agentmods" height="20"></a>
Per session 903 This file is loaded in full into every session.
When invoked 903 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00903 $0.00903
Opus 5 $0.00451 $0.00451
Sonnet 5 $0.00181 $0.00181
Haiku 4.5 $0.00090 $0.00090

Measured 2d ago against content hash b0f4dda7cfa5, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

rust scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/rust.mdc · 71 lines

How it starts

The opening of the file, as written. The whole thing — 71 lines — stays where its author put it; the contents beside it link to each section on GitHub.


description: Rules for writing Rust services at PostHog. Focuses on writing async Rust with Tokio and encoding general Rust best practices from the Rust book and docs. globs: *.rs, rust/

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 with auxiliary verbs (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.

Performance Optimization:

  • try to maintain zero copy for all bytes
  • try to avoid dynamic functions
  • always prefer approaches that do not require allocation of new Strings or Vecs unless specifically requested

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, avoid using unwrap() without proper error handling.
  • Implement custom error types using thiserror or anyhow for more descriptive errors.
  • Implement proper error logging and user-friendly messages
  • Prioritize error handling: handle errors and edge cases early in the code
  • Use early returns and guard clauses
  • 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.

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.

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.

Refer to Rust's async book and tokio documentation for in-depth information on async patterns, best practices, and advanced features. Follow Rust docs for style, examples, and code.

Read the full file on GitHub · 71 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 71 lines · 903 tokens per session scan A b0f4dda7cfa5

Subscribe to this mod's changes

rust is a cursor rule published in the GitHub repository PostHog/posthog-foss (714 stars, last pushed today), licensed MIT. It adds 903 tokens to every session, about $0.0045 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.