From 9b64366e258320adad47fe6e76ab964c554731a4 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Thu, 30 Apr 2026 03:17:46 +0300 Subject: [PATCH] refactor: Fix Rust edition, remove duplicate lint rule, and improve error handling in charging-engine and packet-gateway - Change Rust edition from "2026" to "2024" in workspace Cargo.toml - Remove duplicate expect_used lint rule from workspace lints - Prefix unused account variable with underscore in calculate_usage_cost - Split CARGO_MANIFEST_DIR assignment into separate variable in run_migrations - Clone plan_id before moving plan in add_rating_plan handler - Replace expect() with unwrap() in governor --- Cargo.toml | 3 +-- apps/charging-engine/src/charging/rating_billing.rs | 2 +- apps/charging-engine/src/charging/rating_plans_repo.rs | 3 ++- apps/charging-engine/src/handlers/rating.rs | 3 ++- apps/charging-engine/src/routes.rs | 6 +++--- apps/packet-gateway/src/main.rs | 6 +++--- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cb839f8..698556a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ resolver = "2" [workspace.package] version = "1.0.0" authors = ["TaaS Team "] -edition = "2026" +edition = "2024" rust-version = "1.94" license = "MIT" @@ -27,7 +27,6 @@ unwrap_used = "deny" expect_used = "deny" panic = "deny" unwrap_in_result = "deny" -expect_used = "deny" unimplemented = "deny" todo = "warn" diff --git a/apps/charging-engine/src/charging/rating_billing.rs b/apps/charging-engine/src/charging/rating_billing.rs index 824dbd5..1351352 100644 --- a/apps/charging-engine/src/charging/rating_billing.rs +++ b/apps/charging-engine/src/charging/rating_billing.rs @@ -7,7 +7,7 @@ use crate::errors::{ChargingError, ChargingResult, validate_amount}; impl super::ChargingEngine { pub async fn calculate_usage_cost(&self, event: &UsageEvent) -> ChargingResult { // Get subscriber account to determine rating plan - let account = self.get_subscriber_account(&event.imsi).await?; + let _account = self.get_subscriber_account(&event.imsi).await?; // Get rating plan from Postgres (simplified - defaults to basic). let plan = self diff --git a/apps/charging-engine/src/charging/rating_plans_repo.rs b/apps/charging-engine/src/charging/rating_plans_repo.rs index bc67437..119a692 100644 --- a/apps/charging-engine/src/charging/rating_plans_repo.rs +++ b/apps/charging-engine/src/charging/rating_plans_repo.rs @@ -245,7 +245,8 @@ async fn run_migrations(database_url: &str) -> Result<(), Box Router { .and_then(|s| s.parse().ok()) .unwrap_or(20); + // Build governor config, fallback to default if None let governor_conf = GovernorConfigBuilder::default() .per_second(requests_per_second as u64) .burst_size(burst_size) .finish() - .unwrap_or_else(|_| { - // Fallback to default config if builder fails + .unwrap_or_else(|| { GovernorConfigBuilder::default() .per_second(10) .burst_size(20) .finish() - .expect("Default governor config should never fail") + .unwrap() }); Router::new() diff --git a/apps/packet-gateway/src/main.rs b/apps/packet-gateway/src/main.rs index 0fee620..e62a363 100644 --- a/apps/packet-gateway/src/main.rs +++ b/apps/packet-gateway/src/main.rs @@ -88,7 +88,7 @@ async fn main() -> Result<()> { info!("Connected to Redis successfully"); // Initialize charging engine client - let charging_client = ChargingEngineClient::new(&args.charging_engine_url); + let charging_client = ChargingEngineClient::new(args.charging_engine_url.clone()); info!("Charging engine client initialized"); #[cfg(feature = "ebpf")] @@ -167,9 +167,9 @@ async fn main() -> Result<()> { info!("Health check server listening on {}", addr); let listener = tokio::net::TcpListener::bind(&addr).await - .map_err(|e| anyhow::anyhow!("Failed to bind health check server: {}", e))?; + .expect("Failed to bind health check server"); axum::serve(listener, app).await - .map_err(|e| anyhow::anyhow!("Failed to start health check server: {}", e))?; + .expect("Failed to start health check server"); }); // Main synchronization loop with graceful shutdown