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
This commit is contained in:
nutcas3
2026-04-30 03:17:46 +03:00
parent cd392894df
commit 9b64366e25
6 changed files with 12 additions and 11 deletions
@@ -7,7 +7,7 @@ use crate::errors::{ChargingError, ChargingResult, validate_amount};
impl super::ChargingEngine {
pub async fn calculate_usage_cost(&self, event: &UsageEvent) -> ChargingResult<f64> {
// 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
@@ -245,7 +245,8 @@ async fn run_migrations(database_url: &str) -> Result<(), Box<dyn std::error::Er
use std::process::Command;
// Change to repo root to find migrations directory
let repo_root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
let manifest_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let repo_root = manifest_dir
.parent()
.and_then(|p| p.parent())
.ok_or("Failed to determine repo root")?;
+2 -1
View File
@@ -66,12 +66,13 @@ pub async fn add_rating_plan(
sms_limit: req.get("sms_limit").and_then(|v| v.as_u64()).unwrap_or(100),
};
let plan_id = plan.plan_id.clone();
state.charging_engine.add_rating_plan(plan).await
.with_context("Failed to add rating plan")?;
Ok(Json(serde_json::json!({
"status": "added",
"plan_id": plan.plan_id,
"plan_id": plan_id,
})))
}
+3 -3
View File
@@ -33,17 +33,17 @@ pub fn create_router(state: AppState) -> 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()