use crate::app_config::{AppConfig, ConsumptionBackend}; use rand::{thread_rng, Rng}; pub type EnergyConsumption = i32; /// Get current electrical energy consumption pub async fn get_curr_consumption() -> anyhow::Result { let backend = AppConfig::get() .consumption_backend .as_ref() .unwrap_or(&ConsumptionBackend::Constant { value: 300 }); match backend { ConsumptionBackend::Constant { value } => Ok(*value), ConsumptionBackend::Random { min, max } => Ok(thread_rng().gen_range(*min..*max)), } }