about summary refs log tree commit diff
diff options
context:
space:
mode:
authorltdk <usr@ltdk.xyz>2023-07-31 13:21:42 -0400
committerltdk <usr@ltdk.xyz>2023-07-31 13:21:42 -0400
commitb64f3c7181ccc66aca595c2b95e5a2c64b9525c6 (patch)
tree904fa3ebbdfccfca143f0d5d142e8009f053946b
parentf65fbe95171033f1d7377f13500de5e13e6f7ca1 (diff)
downloadrust-b64f3c7181ccc66aca595c2b95e5a2c64b9525c6.tar.gz
rust-b64f3c7181ccc66aca595c2b95e5a2c64b9525c6.zip
Add note on gap for MIN/MAX
-rw-r--r--library/core/src/char/methods.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs
index cca32c2dd37..c875f4503be 100644
--- a/library/core/src/char/methods.rs
+++ b/library/core/src/char/methods.rs
@@ -11,9 +11,27 @@ 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();
+    /// assert!(dist < size);
+    /// ```
+    ///
+    /// 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);
@@ -26,6 +44,23 @@ impl char {
 
     /// 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();
+    /// assert!(dist < size);
+    /// ```
+    ///
+    /// Despite this gap, the [`MIN`] and `MAX` values can be used as bounds for
+    /// all `char` values.
+    ///
+    /// [`MIN`]: char::MIN
+    ///
     /// # Examples
     ///
     /// ```