Improve from_into.rs #2282
Unanswered
jeffrey-cochran
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I failed these tests initially, but when I looked at them, I realized that a reasonable interpretation of the instructions would produce different results.
Specifically, the tests
test_bad_age
,test_missing_age
, andtest_missing_name
are not testing the behavior that I inferred from the instructions. I understood the instruction (4) to be "If the name is empty, return [a Person with the default name]" and (6) to be "If parsing the age fails, return [a Person with the default age]".The reason my brain immediately jumped to this incorrect conclusion is that the context makes it clear that, in such a case, it's possilbe the rest of the information is valid--so why throw away valid information?
I don't think the tests or instructions are wrong, only that they could be clearer (or better).
For reference, here is what my initial implementation looked like:
Beta Was this translation helpful? Give feedback.
All reactions