The checked_* functions returning Option should be replaced with try_*

Take for example fn checked_div(self, other: i8) -> Option<i8>

assert_eq!((-128i8).checked_div(-1), None);
assert_eq!((1i8).checked_div(0), None);

I would argue that these are different error cases. They should give different error messages. Of course checked_* functions can’t be taken out, but they can be deprecated in favor of try_* functions that return a Result.

So in this case it would be fn try_div(self, other: i8) -> Result<i8, DivError> so that it would actually tell you if it encountered a division by zero, underflow, overflow, etc.

Another advantage is that you could use these functions with the try! macro since they would return a Result.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.