Description
Proposal
Problem statement
Several standard primitive types offer MIN
and MAX
constants, which have a variety of use cases across the ecosystem. Unfortunately, char
only offers a MAX
constant, and not MIN
.
Motivating examples or use cases
While Rust doesn't offer generic traits for minimum/maximum bounds on types, the standard MIN
and MAX
constants make implementing such functionality across a wide variety of types easy, since macros can simply expect <$t>::MIN
and <$t>::MAX
to exist. Unfortunately, char
only has MAX
, not MIN
.
One of the arguments for why char::MAX
exists is that it's difficult to remember and easy to mess up. For example, the literal '\u{10FFFF}'
could easily be accidentally typed as \u{10FFF}
and would be easy to miss. However, char::MAX
is much harder to mistype without breaking, and is much clearer about its intent.
Compare this to the minimum value '\0'
which is substantially easier to remember and a lot clearer. However, keep in mind that unsigned integers have an even simpler minimum, 0
, and these also have MIN
constants.
Solution sketch
impl char {
const MIN: char = '\0';
}
Alternatives
The primary alternative is to simply not offer this constant, if the motivation doesn't justify it.
Links and related work
N/A
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
- We think this problem seems worth solving, and the standard library might be the right place to solve it.
- We think that this probably doesn't belong in the standard library.
Second, if there's a concrete solution:
- We think this specific solution looks roughly right, approved, you or someone else should implement this. (Further review will still happen on the subsequent implementation PR.)
- We're not sure this is the right solution, and the alternatives or other materials don't give us enough information to be sure about that. Here are some questions we have that aren't answered, or rough ideas about alternatives we'd want to see discussed.