Skip to content

Commit feb0673

Browse files
committed
Auto merge of #114299 - clarfonthey:char-min, r=dtolnay,BurntSushi
Add char::MIN ACP: rust-lang/libs-team#252 Tracking issue: #114298 r? `@rust-lang/libs-api`
2 parents 1e746d7 + 9fce8ab commit feb0673

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

library/core/src/char/methods.rs

+51-1
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,66 @@ use crate::unicode::{self, conversions};
99
use super::*;
1010

1111
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+
1245
/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
1346
///
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+
///
1464
/// # Examples
1565
///
1666
/// ```
1767
/// # fn something_which_returns_char() -> char { 'a' }
1868
/// let c: char = something_which_returns_char();
1969
/// assert!(c <= char::MAX);
2070
///
21-
/// let value_at_max = char::MAX as u32;
71+
/// let value_at_max = u32::from(char::MAX);
2272
/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}'));
2373
/// assert_eq!(char::from_u32(value_at_max + 1), None);
2474
/// ```

0 commit comments

Comments
 (0)