-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
refactor: avoid unwrap examples #4001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
a73f74c to
bf1e56e
Compare
examples/params.rs
Outdated
| .status(StatusCode::UNPROCESSABLE_ENTITY) | ||
| .body(full(MISSING)) | ||
| .unwrap()); | ||
| .expect("missing should be valid")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also do:
let mut response = Response::new(full(MISSING));
*response.status_mut() = StatusCode::UNPROCESSABLE_ENTITY;
return Ok(response);I am not sure which one is actually better.
bf1e56e to
3c1626c
Compare
seanmonstar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning these up!
Just one general comment that applies to several of these: it's never the body that would cause an error. It's only every status(), header(), or uri() that is parsing into an http type that could error. So the expect should mention "constant status won't error", instead of "missing should be valid".
Good point! Updated. Thank you. |
close #3984
Just avoid
unwrapas much as possible. Use expect to assert that it will always succeed.