Skip to content

Conversation

@0xPoe
Copy link

@0xPoe 0xPoe commented Dec 30, 2025

close #3984

Just avoid unwrap as much as possible. Use expect to assert that it will always succeed.

.status(StatusCode::UNPROCESSABLE_ENTITY)
.body(full(MISSING))
.unwrap());
.expect("missing should be valid"));
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Examples full of unsafe usage of .unwrap()

1 participant