Skip to content

Commit 3c1626c

Browse files
committed
refactor: avoid unwrap in params example
1 parent 4ecad77 commit 3c1626c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

examples/params.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async fn param_example(
5252
return Ok(Response::builder()
5353
.status(StatusCode::UNPROCESSABLE_ENTITY)
5454
.body(full(MISSING))
55-
.unwrap());
55+
.expect("missing should be valid"));
5656
};
5757
let number = if let Some(n) = params.get("number") {
5858
if let Ok(v) = n.parse::<f64>() {
@@ -61,13 +61,13 @@ async fn param_example(
6161
return Ok(Response::builder()
6262
.status(StatusCode::UNPROCESSABLE_ENTITY)
6363
.body(full(NOTNUMERIC))
64-
.unwrap());
64+
.expect("notnumeric should be valid"));
6565
}
6666
} else {
6767
return Ok(Response::builder()
6868
.status(StatusCode::UNPROCESSABLE_ENTITY)
6969
.body(full(MISSING))
70-
.unwrap());
70+
.expect("missing should be valid"));
7171
};
7272

7373
// Render the response. This will often involve
@@ -86,7 +86,7 @@ async fn param_example(
8686
return Ok(Response::builder()
8787
.status(StatusCode::UNPROCESSABLE_ENTITY)
8888
.body(full(MISSING))
89-
.unwrap());
89+
.expect("missing should be valid"));
9090
};
9191
let params = form_urlencoded::parse(query.as_bytes())
9292
.into_owned()
@@ -97,15 +97,15 @@ async fn param_example(
9797
return Ok(Response::builder()
9898
.status(StatusCode::UNPROCESSABLE_ENTITY)
9999
.body(full(MISSING))
100-
.unwrap());
100+
.expect("missing should be valid"));
101101
};
102102
let body = format!("You requested {}", page);
103103
Ok(Response::new(full(body)))
104104
}
105105
_ => Ok(Response::builder()
106106
.status(StatusCode::NOT_FOUND)
107107
.body(empty())
108-
.unwrap()),
108+
.expect("not found should be valid")),
109109
}
110110
}
111111

0 commit comments

Comments
 (0)