rust

rust is a cursor rule for coding agents from PatrickJS/awesome-cursorrules. It costs 0 tokens per session (1,025 once invoked), scanned A, original, CC0-1.0.

A set of rules for writing Solana smart contracts in Rust with Anchor and the Solana SDK. Solana is a blockchain platform, and Anchor is a framework that helps structure and validate its on-chain programs.

In plain words
What is it for?
Use it when creating or reviewing Solana programs, including account validation, instructions, state, serialization, cross-program calls, and fixed-point arithmetic.
Why use it?
It helps prevent unsafe account handling, serialization errors, and incorrect on-chain data calculations. It also keeps program instructions, state, errors, and reusable logic separated.

Cursor rule

About the project

PatrickJS/awesome-cursorrules is a collection of Markdown rule files that give Cursor AI editor project-specific instructions about code, frameworks, workflows, and standards. Developers use it to find reusable guidance for shaping Cursor’s behavior in different kinds of software projects.

PatrickJS/awesome-cursorrules · 40,725 stars · on GitHub

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/patrickjs/awesome-cursorrules/rust
Clone the repo
git clone --depth 1 https://github.com/PatrickJS/awesome-cursorrules

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/patrickjs/awesome-cursorrules/rust.svg)](https://agentmods.dev/rules/patrickjs/awesome-cursorrules/rust)
Your own site
<a href="https://agentmods.dev/rules/patrickjs/awesome-cursorrules/rust"><img src="https://agentmods.dev/badge/rules/patrickjs/awesome-cursorrules/rust.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,025 The whole file, excluding the scripts and references it only reads on demand.
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 $0.00000 $0.01025
Opus 5 $0.00000 $0.00513
Sonnet 5 $0.00000 $0.00205
Haiku 4.5 $0.00000 $0.00103

Measured yesterday against content hash 6f2ca794ce37, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 yesterday.

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.

Origin

Copies of this mod

2 near-identical copies found in the catalogue:

  • rust — 98% identical, 4 lines differ
  • rust — 95% identical, 1 lines differ
rules/rust.mdc · 86 lines

How it starts

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

Rust + Solana (Anchor) Best Practices

Program Structure

  • Structure Solana programs using Anchor framework standards
  • Place program entrypoint logic in lib.rs, not main.rs
  • Organize handlers into modules (e.g., initialize, update, close)
  • Separate state definitions, errors, instructions, and utils
  • Group reusable logic under a utils module (e.g., account validation)
  • Use declare_id!() to define program ID

Anchor Framework

  • Use #[derive(Accounts)] for all instruction contexts
  • Validate accounts strictly using constraint macros (e.g., #[account(mut)], seeds, bump])
  • Define all state structs with #[account] and #[derive(AnchorSerialize, AnchorDeserialize)]
  • Prefer Init, Close, Realloc, Mut, and constraint macros to avoid manual deserialization
  • Use ctx.accounts to access validated context accounts
  • Handle CPI (Cross-Program Invocation) calls via Anchor’s CPI helpers

Serialization

  • Use Borsh or Anchor's custom serializer (not Serde) for on-chain data
  • Always include #[account(zero_copy)] or #[repr(C)] for packed structures
  • Avoid floating point types — use u64, u128, or fixed-point math
  • Zero out or close unused accounts to reduce rent costs

Testing

  • Write tests in TypeScript using Anchor’s Mocha + Chai setup (tests/*.ts)
  • Use anchor.workspace.MyProgram to load deployed contracts
  • Use provider.simulate() to inspect failed txs
  • Spin up a local validator (anchor test) and reset between tests
  • Airdrop SOL to wallets with provider.connection.requestAirdrop(...)
  • Validate program logs using tx.confirmation.logMessages

Solana SDK (Manual)

  • Use solana_program crate when not using Anchor (bare-metal programs)
  • Carefully deserialize accounts using AccountInfo, try_from_slice_unchecked
  • Use solana_program::msg! for lightweight debugging logs
  • Verify accounts via is_signer, is_writable, key == expected
  • Never panic! Use ProgramError::Custom(u32) or ErrorCode enums

Read the full file on GitHub · 86 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. yesterday First seen · 86 lines · 0 tokens per session scan A 6f2ca794ce37

Subscribe to this mod's changes

rust is a cursor rule published in the GitHub repository PatrickJS/awesome-cursorrules (40,725 stars, last pushed 3mo ago), licensed CC0-1.0. It costs nothing until one of its globs matches a file; then it loads 1,025 tokens. 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.