From fb55618848c8f36b80deca386bb017a81418e25a Mon Sep 17 00:00:00 2001 From: amikai Date: Sun, 5 Oct 2025 01:26:15 +0800 Subject: [PATCH] Refactor from match to if-else --- weather-server-rust/src/main.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/weather-server-rust/src/main.rs b/weather-server-rust/src/main.rs index 3ca4b6f..96192fd 100644 --- a/weather-server-rust/src/main.rs +++ b/weather-server-rust/src/main.rs @@ -1,11 +1,12 @@ use anyhow::Result; use rmcp::{ + ServerHandler, ServiceExt, handler::server::{router::tool::ToolRouter, tool::Parameters}, model::*, - schemars, tool, tool_handler, tool_router, ServerHandler, ServiceExt, + schemars, tool, tool_handler, tool_router, }; -use serde::de::DeserializeOwned; use serde::Deserialize; +use serde::de::DeserializeOwned; const NWS_API_BASE: &str = "https://api.weather.gov"; const USER_AGENT: &str = "weather-app/1.0"; @@ -165,20 +166,14 @@ impl Weather { }): Parameters, ) -> String { let points_url = format!("{NWS_API_BASE}/points/{latitude},{longitude}"); - let points_data = match make_nws_request::(&points_url).await { - Ok(data) => data, - Err(_) => { - return "Unable to fetch forecast data for this location.".to_string(); - } + let Ok(points_data) = make_nws_request::(&points_url).await else { + return "Unable to fetch forecast data for this location.".to_string(); }; let forecast_url = points_data.properties.forecast; - let forecast_data = match make_nws_request::(&forecast_url).await { - Ok(data) => data, - Err(_) => { - return "Unable to fetch forecast data for this location.".to_string(); - } + let Ok(forecast_data) = make_nws_request::(&forecast_url).await else { + return "Unable to fetch forecast data for this location.".to_string(); }; let periods = &forecast_data.properties.periods;