Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify documentation on char::MAX #93392

Merged
merged 2 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ use super::*;

#[lang = "char"]
impl char {
/// The highest valid code point a `char` can have.
/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
///
/// A `char` is a [Unicode Scalar Value], which means that it is a [Code
/// Point], but only ones within a certain range. `MAX` is the highest valid
/// code point that's a valid [Unicode Scalar Value].
/// # Examples
///
/// ```
/// # fn something_which_returns_char() -> char { 'a' }
/// let c: char = something_which_returns_char();
/// assert!(c <= char::MAX);
///
/// [Unicode Scalar Value]: https://www.unicode.org/glossary/#unicode_scalar_value
/// [Code Point]: https://www.unicode.org/glossary/#code_point
/// let value_at_max = char::MAX as u32;
/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}'));
/// assert_eq!(char::from_u32(value_at_max + 1), None);
/// ```
#[stable(feature = "assoc_char_consts", since = "1.52.0")]
pub const MAX: char = '\u{10ffff}';

Expand Down
17 changes: 11 additions & 6 deletions library/core/src/char/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,19 @@ const MAX_THREE_B: u32 = 0x10000;
Cn Unassigned a reserved unassigned code point or a noncharacter
*/

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

Expand Down