Skip to content

Commit

Permalink
Auto merge of rust-lang#114299 - clarfonthey:char-min, r=dtolnay,Burn…
Browse files Browse the repository at this point in the history
…tSushi

Add char::MIN

ACP: rust-lang/libs-team#252
Tracking issue: rust-lang#114298

r? `@rust-lang/libs-api`
  • Loading branch information
bors committed Sep 8, 2023
2 parents 1e746d7 + 9fce8ab commit feb0673
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,66 @@ use crate::unicode::{self, conversions};
use super::*;

impl char {
/// The lowest valid code point a `char` can have, `'\0'`.
///
/// Unlike integer types, `char` actually has a gap in the middle,
/// meaning that the range of possible `char`s is smaller than you
/// might expect. Ranges of `char` will automatically hop this gap
/// for you:
///
/// ```
/// #![feature(char_min)]
/// let dist = u32::from(char::MAX) - u32::from(char::MIN);
/// let size = (char::MIN..=char::MAX).count() as u32;
/// assert!(size < dist);
/// ```
///
/// Despite this gap, the `MIN` and [`MAX`] values can be used as bounds for
/// all `char` values.
///
/// [`MAX`]: char::MAX
///
/// # Examples
///
/// ```
/// #![feature(char_min)]
/// # fn something_which_returns_char() -> char { 'a' }
/// let c: char = something_which_returns_char();
/// assert!(char::MIN <= c);
///
/// let value_at_min = u32::from(char::MIN);
/// assert_eq!(char::from_u32(value_at_min), Some('\0'));
/// ```
#[unstable(feature = "char_min", issue = "114298")]
pub const MIN: char = '\0';

/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
///
/// Unlike integer types, `char` actually has a gap in the middle,
/// meaning that the range of possible `char`s is smaller than you
/// might expect. Ranges of `char` will automatically hop this gap
/// for you:
///
/// ```
/// #![feature(char_min)]
/// let dist = u32::from(char::MAX) - u32::from(char::MIN);
/// let size = (char::MIN..=char::MAX).count() as u32;
/// assert!(size < dist);
/// ```
///
/// Despite this gap, the [`MIN`] and `MAX` values can be used as bounds for
/// all `char` values.
///
/// [`MIN`]: char::MIN
///
/// # Examples
///
/// ```
/// # 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;
/// let value_at_max = u32::from(char::MAX);
/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}'));
/// assert_eq!(char::from_u32(value_at_max + 1), None);
/// ```
Expand Down

0 comments on commit feb0673

Please sign in to comment.