Skip to content

Commit b64f3c7

Browse files
committed
Add note on gap for MIN/MAX
1 parent f65fbe9 commit b64f3c7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

library/core/src/char/methods.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,27 @@ use super::*;
1111
impl char {
1212
/// The lowest valid code point a `char` can have, `'\0'`.
1313
///
14+
/// Unlike integer types, `char` actually has a gap in the middle,
15+
/// meaning that the range of possible `char`s is smaller than you
16+
/// might expect. Ranges of `char` will automatically hop this gap
17+
/// for you:
18+
///
19+
/// ```
20+
/// #![feature(char_min)]
21+
/// let dist = u32::from(char::MAX) - u32::from(char::MIN);
22+
/// let size = (char::MIN..=char::MAX).count();
23+
/// assert!(dist < size);
24+
/// ```
25+
///
26+
/// Despite this gap, the `MIN` and [`MAX`] values can be used as bounds for
27+
/// all `char` values.
28+
///
29+
/// [`MAX`]: char::MAX
30+
///
1431
/// # Examples
1532
///
1633
/// ```
34+
/// #![feature(char_min)]
1735
/// # fn something_which_returns_char() -> char { 'a' }
1836
/// let c: char = something_which_returns_char();
1937
/// assert!(char::MIN <= c);
@@ -26,6 +44,23 @@ impl char {
2644

2745
/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
2846
///
47+
/// Unlike integer types, `char` actually has a gap in the middle,
48+
/// meaning that the range of possible `char`s is smaller than you
49+
/// might expect. Ranges of `char` will automatically hop this gap
50+
/// for you:
51+
///
52+
/// ```
53+
/// #![feature(char_min)]
54+
/// let dist = u32::from(char::MAX) - u32::from(char::MIN);
55+
/// let size = (char::MIN..=char::MAX).count();
56+
/// assert!(dist < size);
57+
/// ```
58+
///
59+
/// Despite this gap, the [`MIN`] and `MAX` values can be used as bounds for
60+
/// all `char` values.
61+
///
62+
/// [`MIN`]: char::MIN
63+
///
2964
/// # Examples
3065
///
3166
/// ```

0 commit comments

Comments
 (0)