Skip to content

Commit fb55618

Browse files
committed
Refactor from match to if-else
1 parent 4e81e6e commit fb55618

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

weather-server-rust/src/main.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use anyhow::Result;
22
use rmcp::{
3+
ServerHandler, ServiceExt,
34
handler::server::{router::tool::ToolRouter, tool::Parameters},
45
model::*,
5-
schemars, tool, tool_handler, tool_router, ServerHandler, ServiceExt,
6+
schemars, tool, tool_handler, tool_router,
67
};
7-
use serde::de::DeserializeOwned;
88
use serde::Deserialize;
9+
use serde::de::DeserializeOwned;
910

1011
const NWS_API_BASE: &str = "https://api.weather.gov";
1112
const USER_AGENT: &str = "weather-app/1.0";
@@ -165,20 +166,14 @@ impl Weather {
165166
}): Parameters<MCPForecastRequest>,
166167
) -> String {
167168
let points_url = format!("{NWS_API_BASE}/points/{latitude},{longitude}");
168-
let points_data = match make_nws_request::<PointsResponse>(&points_url).await {
169-
Ok(data) => data,
170-
Err(_) => {
171-
return "Unable to fetch forecast data for this location.".to_string();
172-
}
169+
let Ok(points_data) = make_nws_request::<PointsResponse>(&points_url).await else {
170+
return "Unable to fetch forecast data for this location.".to_string();
173171
};
174172

175173
let forecast_url = points_data.properties.forecast;
176174

177-
let forecast_data = match make_nws_request::<ForecastResponse>(&forecast_url).await {
178-
Ok(data) => data,
179-
Err(_) => {
180-
return "Unable to fetch forecast data for this location.".to_string();
181-
}
175+
let Ok(forecast_data) = make_nws_request::<ForecastResponse>(&forecast_url).await else {
176+
return "Unable to fetch forecast data for this location.".to_string();
182177
};
183178

184179
let periods = &forecast_data.properties.periods;

0 commit comments

Comments
 (0)