Skip to content

Commit 9aaf52b

Browse files
committed
(#93392) Update char::MAX docs and core::char::MAX
1 parent 2fb617c commit 9aaf52b

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

library/core/src/char/methods.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ use super::*;
99

1010
#[lang = "char"]
1111
impl char {
12-
/// The highest valid code point a `char` can have, 0x10FFFF.
12+
/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
1313
///
14-
/// A [Code Point] is any value between zero and `char::MAX`, inclusive. A
15-
/// `char` is a [Unicode Scalar Value], which is a Code Point that is not
16-
/// in the range `0xD800..=0xDFFF`.
14+
/// # Examples
15+
///
16+
/// ```
17+
/// # fn something_which_returns_char() -> char { 'a' }
18+
/// let c: char = something_which_returns_char();
19+
/// assert!(c <= char::MAX);
1720
///
18-
/// [Unicode Scalar Value]: https://www.unicode.org/glossary/#unicode_scalar_value
19-
/// [Code Point]: https://www.unicode.org/glossary/#code_point
21+
/// let value_at_max = char::MAX as u32;
22+
/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}'));
23+
/// assert_eq!(char::from_u32(value_at_max + 1), None);
24+
/// ```
2025
#[stable(feature = "assoc_char_consts", since = "1.52.0")]
2126
pub const MAX: char = '\u{10ffff}';
2227

library/core/src/char/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,19 @@ const MAX_THREE_B: u32 = 0x10000;
8989
Cn Unassigned a reserved unassigned code point or a noncharacter
9090
*/
9191

92-
/// The highest valid code point a `char` can have.
92+
/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
9393
///
94-
/// A [`char`] is a [Unicode Scalar Value], which means that it is a [Code
95-
/// Point], but only ones within a certain range. `MAX` is the highest valid
96-
/// code point that's a valid [Unicode Scalar Value].
94+
/// # Examples
9795
///
98-
/// [Unicode Scalar Value]: https://www.unicode.org/glossary/#unicode_scalar_value
99-
/// [Code Point]: https://www.unicode.org/glossary/#code_point
96+
/// ```
97+
/// # fn something_which_returns_char() -> char { 'a' }
98+
/// let c: char = something_which_returns_char();
99+
/// assert!(c <= char::MAX);
100+
///
101+
/// let value_at_max = char::MAX as u32;
102+
/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}'));
103+
/// assert_eq!(char::from_u32(value_at_max + 1), None);
104+
/// ```
100105
#[stable(feature = "rust1", since = "1.0.0")]
101106
pub const MAX: char = char::MAX;
102107

0 commit comments

Comments
 (0)