posthog-foss / rules
Cursor rule721 starsChanged 56 days agoMITView on GitHub
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.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- PostHog/posthogword for word, first seen Oct 4, 2026
Other versions1 project uses a version of this.
Word for word · 1
- PostHog/posthog★ 40k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository119 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- common/CLAUDE.mdCLAUDE.md
- proto/CLAUDE.mdCLAUDE.md
- rust/CLAUDE.mdCLAUDE.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/react-typescript.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-llm-gateway-paritySkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- autoresolving-pr-conflictsSkill
- building-product-empty-statesSkill
- clickhouse-migrationsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- finding-llm-gateway-migration-candidatesSkill
- fixing-flaky-testsSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- implementing-mcp-ui-appsSkill
- implementing-warehouse-sourcesSkill
- improving-drf-endpointsSkill
- improving-mcp-toolsSkill
- ingestion-pipeline-doctor-nodejsSkill
- The first 60 shown.
The file
Show its rules and text
We split this rust.mdc into the rules it gives an agent
26 rules. About 0 are common, 9 are distinctive, and 17 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
17
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Write clear, concise, and idiomatic Rust code with accurate examples.
- Very specific: line 10
Use async programming paradigms effectively, leveraging tokio for concurrency.
- Very specific: line 12
Use expressive variable names that convey intent with auxiliary verbs (e.g., is_ready, has_data).
- Distinctive: line 14
Avoid code duplication; use functions and modules to encapsulate reusable logic.
- Distinctive: line 15
Write code with safety, concurrency, and performance in mind, embracing Rust's ownership and type system.
- Very specific: line 18
Use tokio as the async runtime for handling asynchronous tasks and I/O.
- Very specific: line 21
Use tokio::select! for managing multiple async tasks and cancellations.
- Distinctive: line 28
always prefer approaches that do not require allocation of new Strings or Vecs unless specifically requested
- Very specific: line 31
Use Rust's tokio::sync::mpsc for asynchronous, multi-producer, single-consumer channels.
- Very specific: line 32
Use tokio::sync::broadcast for broadcasting messages to multiple consumers.
- Distinctive: line 34
Prefer bounded channels for backpressure.
- Very specific: line 35
Use tokio::sync::Mutex and tokio::sync::RwLock for shared state across tasks, avoiding deadlocks.
- Very specific: line 39
Use ? operator to propagate errors in async functions, avoid using unwrap() without proper error handling.
- Distinctive: line 43
Use early returns and guard clauses
- Very specific: line 44
Use .await responsibly, ensuring safe points for context switching.
- Very specific: line 47
Write unit tests with tokio::test for async tests.
- Very specific: line 48
Use tokio::time::pause for testing time-dependent code without real delays.
- Distinctive: line 50
Use mocks and fakes for external dependencies in tests.
- Distinctive: line 54
Avoid blocking operations inside async functions.
- Very specific: line 55
Use tokio::task::yield_now to yield control in cooperative multitasking scenarios.
- Very specific: line 57
Use tokio::time::sleep and tokio::time::interval for efficient time-based operations.
- Very specific: line 60
Use tokio for async runtime and task management.
- Very specific: line 62
Use serde for serialization/deserialization.
- Very specific: line 63
Use sqlx or tokio-postgres for async database interactions.
- Very specific: line 68
Use environment variables for configuration management (e.g., dotenv crate).
- Distinctive: line 69
Ensure code is well-documented with inline comments and Rustdoc.
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
--- 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.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

