from_env

Function from_env 

Source
pub fn from_env() -> Result<BrowserPoolConfig, BrowserPoolError>
Expand description

Load configuration from environment variables.

Reads configuration from environment variables with sensible defaults. Also loads app.env file if present (via dotenvy).

§Environment File

This function looks for an app.env file in the current directory and loads it if present. The file is optional - if not found, environment variables and defaults are used.

§Environment Variables

  • BROWSER_POOL_SIZE: Maximum pool size (default: 5)
  • BROWSER_WARMUP_COUNT: Warmup browser count (default: 3)
  • BROWSER_TTL_SECONDS: Browser TTL in seconds (default: 3600)
  • BROWSER_WARMUP_TIMEOUT_SECONDS: Warmup timeout (default: 60)
  • BROWSER_PING_INTERVAL_SECONDS: Health check interval (default: 15)
  • BROWSER_MAX_PING_FAILURES: Max ping failures (default: 3)

§Errors

Returns BrowserPoolError::Configuration if configuration values are invalid.

§Example

use html2pdf_api::config::env::from_env;

// Set environment variables before calling
std::env::set_var("BROWSER_POOL_SIZE", "10");

let config = from_env()?;
assert_eq!(config.max_pool_size, 10);