pn-rust-backend

pn-rust-backend is a cursor rule for coding agents from perniemann/pnCore. It costs 0 tokens per session (910 once invoked), scanned A, original, MIT.

Rust backend coding rules for API and server programs built with frameworks such as Axum or Actix-web. They cover errors, asynchronous work, ownership, and safe handling of external calls.

In plain words
What is it for?
Writing Rust API handlers, database and HTTP calls, shared application state, error types, asynchronous I/O, and timeout handling.
Why use it?
They help prevent crashes, blocked server tasks, hanging network requests, and errors that are difficult to diagnose.

Cursor rule

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/perniemann/pncore/pn-rust-backend
Clone the repo
git clone --depth 1 https://github.com/perniemann/pnCore

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 pn-rust-backend

README.md
[![agentmods](https://agentmods.dev/badge/rules/perniemann/pncore/pn-rust-backend.svg)](https://agentmods.dev/rules/perniemann/pncore/pn-rust-backend)
Your own site
<a href="https://agentmods.dev/rules/perniemann/pncore/pn-rust-backend"><img src="https://agentmods.dev/badge/rules/perniemann/pncore/pn-rust-backend.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 910 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.00910
Opus 5 $0.00000 $0.00455
Sonnet 5 $0.00000 $0.00182
Haiku 4.5 $0.00000 $0.00091

Measured 3d ago against content hash 0ceeaf0f0749, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

pn-rust-backend 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 3d 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.

packages/pn-core-mcp/content/rules/pn-rust-backend.mdc · 50 lines

How it starts

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

Rust / backend rules

Error handling

  • Use Result<T, E> for all fallible operations. Never .unwrap() or .expect() in production code paths — use ? to propagate or handle explicitly.
  • Define a crate-level error enum using thiserror. Use anyhow in binary crates (applications); use thiserror in library crates.
  • Prefer ? over match for error propagation in linear flows. Use match when branches have different recovery strategies.
  • Provide context when wrapping errors: .map_err(|e| AppError::Db(e.to_string())) with enough detail to debug without a stack trace.

Async

  • Use tokio as the async runtime. All I/O-bound operations must be async — never block the executor with synchronous I/O (std::fs, std::thread::sleep).
  • For CPU-heavy work inside async code: use tokio::task::spawn_blocking.
  • Use tokio::timeout or tower::timeout to bound all external calls (DB, HTTP). Unbounded I/O awaits cause silent hangs.
  • Share state across handlers via Arc<AppState> passed through Axum's State extractor or Actix's web::Data.

Ownership and types

  • Prefer references over cloning for large data. Profile before adding .clone() to work around borrow checker pushback.
  • Use Arc<T> for shared ownership in async code; Rc<T> is not Send. Use Mutex/RwLock only when mutation is needed.
  • Use newtype wrappers to distinguish semantically different values of the same primitive: struct UserId(i64) prevents confusing user_id with order_id.
  • Use Option<T> for values that may legitimately be absent. Avoid sentinel values (-1, "") to represent absence.

Secrets and config

  • All config and secrets from environment variables. Use std::env::var("VAR").expect("VAR required") at startup — fail fast on missing config.
  • Use dotenvy in development; never commit .env to git.
  • Consider config crate or envy for typed, validated config structs derived from environment.

Web framework patterns (Axum / Actix)

  • Extract shared dependencies (DB pool, config, HTTP client) into AppState. Inject via State<Arc<AppState>> (Axum) or Data<AppState> (Actix).
  • Implement IntoResponse (Axum) or ResponseError (Actix) on error types for centralized response formatting.
  • Use typed extractors for request parsing (Json<CreateUserRequest>) — validators run before the handler body.
  • Apply middleware at the router level (logging, auth, rate limiting) rather than in individual handlers.

Read the full file on GitHub · 50 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. 3d ago First seen · 50 lines · 0 tokens per session scan A 0ceeaf0f0749

Subscribe to this mod's changes

pn-rust-backend is a cursor rule published in the GitHub repository perniemann/pnCore (0 stars, last pushed today), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 910 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-08-31.