configuration

A set of Rust guidelines for reading, validating, and updating application settings. It covers several file formats, environment-variable overrides, and optional live reloading while a program runs.

In plain words
What is it for?
Use it when adding configuration files, environment-based settings, validation, tests, or hot reloading to a Rust application.
Why use it?
It provides a consistent way to manage settings and catch invalid configuration before it causes runtime problems.

Cursor rule for 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/tyrchen/cursor-rust-rules/configuration
Clone the repo
git clone --depth 1 https://github.com/tyrchen/cursor-rust-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 3,717 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.03717
Opus 5 $0.00000 $0.01858
Sonnet 5 $0.00000 $0.00743
Haiku 4.5 $0.00000 $0.00372

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

Security

Grade A, and why

configuration 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/features/configuration.mdc · 558 lines

How it starts

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

⚙️ RUST CONFIGURATION MANAGEMENT

TL;DR: Comprehensive patterns for configuration management in Rust applications, including multi-format parsing, validation, hot-reloading, and environment-based overrides.

🔍 CONFIGURATION STRATEGY

graph TD
    Start["Configuration Needs"] --> Format{"Configuration<br>Format?"}

    Format -->|Single| SingleFormat["Single Format Parsing"]
    Format -->|Multiple| MultiFormat["Multi-Format Support"]

    SingleFormat --> Validation["Configuration Validation"]
    MultiFormat --> Validation

    Validation --> Environment["Environment Overrides"]
    Environment --> Runtime{"Runtime<br>Updates?"}

    Runtime -->|Static| StaticConfig["Static Configuration"]
    Runtime -->|Dynamic| HotReload["Hot Reloading"]

    StaticConfig --> Testing["Configuration Testing"]
    HotReload --> Watching["File System Watching"]
    Watching --> AtomicUpdate["Atomic Updates"]
    AtomicUpdate --> Testing

    Testing --> Production["Production Configuration"]

    style Start fill:#4da6ff,stroke:#0066cc,color:white
    style MultiFormat fill:#4dbb5f,stroke:#36873f,color:white
    style HotReload fill:#ffa64d,stroke:#cc7a30,color:white
    style AtomicUpdate fill:#d94dbb,stroke:#a3378a,color:white

🎯 CONFIGURATION PRINCIPLES

Multi-Format Configuration Support

use figment::{Figment, providers::{Format, Yaml, Toml, Json, Env}};
use serde::{Deserialize, Serialize};
use validator::{Validate, ValidationError};

// ✅ Configuration structure with validation
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
#[serde(rename_all = "snake_case")]
pub struct AppConfig {
    #[validate(length(min = 1, max = 100))]
    pub name: String,

    #[validate(range(min = 1, max = 65535))]
    pub port: u16,

    #[serde(default = "default_host")]
    #[validate(length(min = 1))]
    pub host: String,

    #[serde(default)]
    pub features: Vec<String>,

    #[validate(nested)]
    pub database: DatabaseConfig,

    #[serde(default)]
    #[validate(nested)]
    pub logging: LoggingConfig,
}

#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct DatabaseConfig {
    #[validate(url)]
    pub url: String,

    #[validate(range(min = 1, max = 1000))]
    #[serde(default = "default_pool_size")]
    pub pool_size: u32,

    #[serde(default = "default_timeout")]
    pub timeout_seconds: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct LoggingConfig {
    #[serde(default = "default_log_level")]
    pub level: String,

    #[serde(default)]
    pub json_format: bool,
}

// Default value functions
fn default_host() -> String { "0.0.0.0".to_string() }
fn default_pool_size() -> u32 { 10 }
fn default_timeout() -> u64 { 30 }
fn default_log_level() -> String { "info".to_string() }

impl AppConfig {
    /// Load configuration from multiple sources with precedence:
    /// 1. Environment variables (highest priority)
    /// 2. config.yaml file
    /// 3. config.toml file
    /// 4. Default values (lowest priority)
    pub fn load() -> Result<Self, ConfigError> {
        let config = Figment::new()
            .merge(Toml::file("config.toml"))
            .merge(Yaml::file("config.yaml"))
            .merge(Json::file("config.json"))
            .merge(Env::prefixed("APP_"))
            .extract()?;

        // Validate the configuration
        config.validate()
            .map_err(ConfigError::Validation)?;

        Ok(config)
    }

    /// Load from a specific file path
    pub fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Self, ConfigError> {
        let path = path.as_ref();
        let extension = path.extension()
            .and_then(|ext| ext.to_str())
            .ok_or_else(|| ConfigError::UnsupportedFormat("Unknown file extension".to_string()))?;

        let figment = match extension.to_lowercase().as_str() {
            "yaml" | "yml" => Figment::new().merge(Yaml::file(path)),
            "toml" => Figment::new().merge(Toml::file(path)),
            "json" => Figment::new().merge(Json::file(path)),
            ext => return Err(ConfigError::UnsupportedFormat(ext.to_string())),
        };

        let config = figment
            .merge(Env::prefixed("APP_"))
            .extract()?;

        config.validate()
            .map_err(ConfigError::Validation)?;

        Ok(config)
    }
}

Read the full file on GitHub · 558 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 · 558 lines · 0 tokens per session scan A 46c7925142cb

Subscribe to this mod's changes

configuration is a cursor rule published in the GitHub repository tyrchen/cursor-rust-rules (27 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 3,717 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-30.