Skip to main content

Crate toxi_config

Crate toxi_config 

Source
Expand description

§Toxi Config

Configuration and environment variable management for Toxi applications. Loads toxi.toml with support for typed config sections, flat [env] tables, namespaced tables, nested overrides, and .env file loading.

§Environment Variable Naming — Fully Flexible

No env var names are forced. The framework adapts to whatever you configure. You choose the names; Toxi reads them.

§Framework Defaults (override in toxi.toml)

Env VarPurposeDefault
TOXI_ENVApp environmentdevelopment
TOXI_SKIP_DOTENVSkip .env loading(unset)

§User-Configurable (set in toxi.toml or .env)

These have sensible defaults — none are required:

Env VarConfig KeyDefault
DATABASE_URL[database] url""
REDIS_URL[cache] redis_url""
JWT_SECRET[security] jwt_secret""
SERVER_HOST[server] host127.0.0.1
SERVER_PORT[server] port3000

§Custom Names via [env] Table

Define your own env var names in toxi.toml:

[env]
MY_DB_URL = "postgres://localhost/myapp"
MY_API_KEY = "secret-123"

Or use namespaced tables for auto-derived names:

[database]
url = "postgres://localhost/myapp"   # becomes DATABASE_URL

[my_service]
api_key = "secret"                   # becomes MY_SERVICE_API_KEY

§Resolution Order (highest to lowest priority)

  1. Real OS environment variables
  2. .env file entries
  3. [env] flat table entries
  4. Known sections ([server], [database], etc.)
  5. Custom namespaced tables

§Quick Start

use toxi_config::Config;

let config = Config::load()
    .map_err(|e| eprintln!("config error: {e}")).unwrap();

let host: String = config.get("server.host")
    .unwrap_or_else(|| "127.0.0.1".to_string());
println!("Server: {host}");

Structs§

AppConfig
Application metadata configuration
CacheConfig
Cache driver configuration (memory or Redis)
Config
Root configuration struct representing an toxi.toml file
DatabaseConfig
Database connection configuration
QueueConfig
Background job queue configuration
SecurityConfig
Security configuration (JWT, CORS, rate limiting)
ServerConfig
HTTP server configuration (host, port, worker count)

Enums§

ConfigError
Errors that can occur during configuration loading and parsing
Environment
Application environment mode