Skip to content

Simplify type cast and remove error handling in protobuf exercise #2755

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

randomPoison
Copy link
Collaborator

While using .try_into().expect() is the more robust solution, I think it's more complex than we want here. We don't really care about error handling in this exercise, so I think a simple as cast is clearer here. I think we should also remove the logic for checking if there are enough bytes left, since it simplifies things and makes the solution easier to read.

Copy link
Collaborator

@djmitche djmitche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other cases where we've removed something that would be likely in "real" Rust, we've gotten more than one PR trying to put it back. I think it would help to add some commentary here to indicate this is omitted deliberately. Maybe that's as simple as "// TODO: Handle invalid lengths"? That would be enough to fend off any PRs, and also provide a jumping-off point for instructors to talk about what might go wrong here (e.g., split_at might panic) and how to handle it.

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.

2 participants