Make control flow a bit less nested
@@ -564,8 +564,10 @@ async fn call_service(
.in_current_span()
.await?;
- if let Some(q) = req.uri().query().map(|x| x.to_string()) {
- if parsed_url.pathinfo.is_empty() {
+ if let (Some(q), true) = (
+ req.uri().query().map(|x| x.to_string()),
+ parsed_url.pathinfo.is_empty(),
+ ) {
let s = tracing::span!(tracing::Level::TRACE, "render worker");
let res = tokio::task::spawn_blocking(move || -> josh::JoshResult<_> {
let _e = s.enter();
@@ -590,25 +592,20 @@ async fn call_service(
})
.in_current_span()
.await?;
- match res {
- Ok(res) => {
- if let Some(res) = res {
- return Ok(Response::builder()
+
+ return Ok(match res {
+ Ok(Some(res)) => Response::builder()
.status(hyper::StatusCode::OK)
- .body(hyper::Body::from(res))?);
- } else {
- return Ok(Response::builder()
+ .body(hyper::Body::from(res))?,
+
+ Ok(None) => Response::builder()
.status(hyper::StatusCode::NOT_FOUND)
- .body(hyper::Body::from("File not found".to_string()))?);
- }
- }
- Err(res) => {
- return Ok(Response::builder()
+ .body(hyper::Body::from("File not found".to_string()))?,
+
+ Err(res) => Response::builder()
.status(hyper::StatusCode::UNPROCESSABLE_ENTITY)
- .body(hyper::Body::from(res.to_string()))?)
- }
- }
- }
+ .body(hyper::Body::from(res.to_string()))?,
+ });
}
let repo_path = serv
