I think that the proposed change is unnecessary and that in fact the existing code is better. An out of range base is almost certainly a coding error and should panic. An out of range character is erroneously formatted input and should return None. An out of range numeric value is probably also a coding error, but in this case it makes some sense to return None (although IMO a panic makes more sense). Of course, as huon notes, it would be better to return a Result, which would make the issue moot.
A far bigger problem is that the names are completely backwards. from_digit converts a number to a digit character (and returns None if the number cannot be converted because itās not in range), and to_digit converts a digit character to a number (and returns None if the character isnāt a digit in the given base). The documentation for to_digit says
Converts a char to the corresponding digit
but this is totally confused about the relevant concepts and representations: characters represent digits; numbers are numbers. And it is only certain characters that can be converted, namely those which are ādigitā characters of the given base ⦠and they are converted to the number (not digit) that they represent. Consider that the character, taken from an input stream, necessarily represents a digit within its context, but once it is converted to a number it is simply a number that can be used without regard to where it came from.
The documentation for from_digit says
Converts a number to the character representing it
This is too is quite confused; what character represents the number 45637? Of course, only certain numbers can be converted ⦠namely, those that result in ādigitsā (which are characters) of the given base. Numbers that are too large to be represented as a digit are carved up with the familiar mod/div loop into a sequence of digits (the set of characters that are the tokens of a radix notation for numbers, developed many centuries ago).
If this isnāt clear enough, consider what the inputs and outputs of functions called to_digits and from_digits would be.
And as a final authority, talk to your local Unicode expert ⦠those folks have to keep their concepts straight, and certainly know what digits are.
So what really ought to be done is to come up with new functions with properly descriptive names (perhaps u32_to_digit and digit_to_u32) that return Result, and deprecate these.