core/
utils.rs

1//! General utilities for the `core` crate.
2
3use std::{env, fmt::Display, str::FromStr};
4
5use tracing::info;
6
7/// Fetches an environment variable, or returns a default value if it is not set.
8pub fn get_env<T: FromStr + Display>(key: &str, default: T) -> T {
9    env::var(key)
10        .unwrap_or(format!("{}", default).to_string())
11        .to_string()
12        .parse()
13        .unwrap_or(default)
14}
15
16/// Prints all environment variables.
17pub fn print_envs() {
18    info!("Environment Vars:");
19    info!(
20        "ENVIRONMENT: {}",
21        get_env("ENVIRONMENT", "PROD".to_string())
22    );
23    info!(
24        "DATABASE_URL: {}",
25        get_env(
26            "DATABASE_URL",
27            "postgresql://user:password@localhost:5432/local".to_string()
28        )
29    );
30    info!(
31        "DEV_DB_TYPE: {}",
32        get_env("DEV_DB_TYPE", "EMBEDDED".to_string())
33    );
34    info!(
35        "SAURON_MODEL_PATH: {}",
36        get_env(
37            "SAURON_MODEL_PATH",
38            "./crates/core/models/yolo11n.onnx".to_string()
39        )
40    );
41    info!(
42        "SAURON_INPUT_SIZE: {}",
43        get_env("SAURON_INPUT_SIZE", 640_i32)
44    );
45    info!(
46        "OBJECT_CORD_TOLERANCE: {}",
47        get_env("OBJECT_CORD_TOLERANCE", 0.0001_f64).abs()
48    );
49}