@@ -9,16 +9,66 @@ use crate::unicode::{self, conversions};
9
9
use super :: * ;
10
10
11
11
impl char {
12
+ /// The lowest valid code point a `char` can have, `'\0'`.
13
+ ///
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() as u32;
23
+ /// assert!(size < dist);
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
+ ///
31
+ /// # Examples
32
+ ///
33
+ /// ```
34
+ /// #![feature(char_min)]
35
+ /// # fn something_which_returns_char() -> char { 'a' }
36
+ /// let c: char = something_which_returns_char();
37
+ /// assert!(char::MIN <= c);
38
+ ///
39
+ /// let value_at_min = u32::from(char::MIN);
40
+ /// assert_eq!(char::from_u32(value_at_min), Some('\0'));
41
+ /// ```
42
+ #[ unstable( feature = "char_min" , issue = "114298" ) ]
43
+ pub const MIN : char = '\0' ;
44
+
12
45
/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
13
46
///
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() as u32;
56
+ /// assert!(size < dist);
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
+ ///
14
64
/// # Examples
15
65
///
16
66
/// ```
17
67
/// # fn something_which_returns_char() -> char { 'a' }
18
68
/// let c: char = something_which_returns_char();
19
69
/// assert!(c <= char::MAX);
20
70
///
21
- /// let value_at_max = char::MAX as u32 ;
71
+ /// let value_at_max = u32::from( char::MAX) ;
22
72
/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}'));
23
73
/// assert_eq!(char::from_u32(value_at_max + 1), None);
24
74
/// ```
0 commit comments