Skip to content

Commit a6bbd0c

Browse files
Improve primitive integers documentation
1 parent 9c1783a commit a6bbd0c

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/libcore/num/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,25 @@ macro_rules! int_impl {
187187
$sub_with_overflow:path,
188188
$mul_with_overflow:path) => {
189189
/// Returns the smallest value that can be represented by this integer type.
190+
///
191+
/// # Examples
192+
///
193+
/// ```
194+
/// assert_eq!(i8::min_value(), -128);
195+
/// ```
190196
#[stable(feature = "rust1", since = "1.0.0")]
191197
#[inline]
192198
pub const fn min_value() -> Self {
193199
(-1 as Self) << ($BITS - 1)
194200
}
195201

196202
/// Returns the largest value that can be represented by this integer type.
203+
///
204+
/// # Examples
205+
///
206+
/// ```
207+
/// assert_eq!(i8::max_value(), 127);
208+
/// ```
197209
#[stable(feature = "rust1", since = "1.0.0")]
198210
#[inline]
199211
pub const fn max_value() -> Self {
@@ -287,6 +299,8 @@ macro_rules! int_impl {
287299
/// Shifts the bits to the left by a specified amount, `n`,
288300
/// wrapping the truncated bits to the end of the resulting integer.
289301
///
302+
/// Please note this isn't the same operation as `<<`!
303+
///
290304
/// # Examples
291305
///
292306
/// Basic usage:
@@ -307,6 +321,8 @@ macro_rules! int_impl {
307321
/// wrapping the truncated bits to the beginning of the resulting
308322
/// integer.
309323
///
324+
/// Please note this isn't the same operation as `>>`!
325+
///
310326
/// # Examples
311327
///
312328
/// Basic usage:
@@ -1249,11 +1265,23 @@ macro_rules! uint_impl {
12491265
$sub_with_overflow:path,
12501266
$mul_with_overflow:path) => {
12511267
/// Returns the smallest value that can be represented by this integer type.
1268+
///
1269+
/// # Examples
1270+
///
1271+
/// ```
1272+
/// assert_eq!(u8::min_value(), 0);
1273+
/// ```
12521274
#[stable(feature = "rust1", since = "1.0.0")]
12531275
#[inline]
12541276
pub const fn min_value() -> Self { 0 }
12551277

12561278
/// Returns the largest value that can be represented by this integer type.
1279+
///
1280+
/// # Examples
1281+
///
1282+
/// ```
1283+
/// assert_eq!(u8::max_value(), 255);
1284+
/// ```
12571285
#[stable(feature = "rust1", since = "1.0.0")]
12581286
#[inline]
12591287
pub const fn max_value() -> Self { !0 }
@@ -1360,6 +1388,8 @@ macro_rules! uint_impl {
13601388
/// Shifts the bits to the left by a specified amount, `n`,
13611389
/// wrapping the truncated bits to the end of the resulting integer.
13621390
///
1391+
/// Please note this isn't the same operation as `<<`!
1392+
///
13631393
/// # Examples
13641394
///
13651395
/// Basic usage:
@@ -1382,6 +1412,8 @@ macro_rules! uint_impl {
13821412
/// wrapping the truncated bits to the beginning of the resulting
13831413
/// integer.
13841414
///
1415+
/// Please note this isn't the same operation as `>>`!
1416+
///
13851417
/// # Examples
13861418
///
13871419
/// Basic usage:

src/libstd/primitive_docs.rs

+30
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ mod prim_f64 { }
506506
///
507507
/// *[See also the `std::i8` module](i8/index.html).*
508508
///
509+
/// However, please note that examples are shared between primitive integer
510+
/// types. So it's normal if you see usage of types like `i64` in there.
511+
///
509512
mod prim_i8 { }
510513

511514
#[doc(primitive = "i16")]
@@ -514,6 +517,9 @@ mod prim_i8 { }
514517
///
515518
/// *[See also the `std::i16` module](i16/index.html).*
516519
///
520+
/// However, please note that examples are shared between primitive integer
521+
/// types. So it's normal if you see usage of types like `i32` in there.
522+
///
517523
mod prim_i16 { }
518524

519525
#[doc(primitive = "i32")]
@@ -522,6 +528,9 @@ mod prim_i16 { }
522528
///
523529
/// *[See also the `std::i32` module](i32/index.html).*
524530
///
531+
/// However, please note that examples are shared between primitive integer
532+
/// types. So it's normal if you see usage of types like `i16` in there.
533+
///
525534
mod prim_i32 { }
526535

527536
#[doc(primitive = "i64")]
@@ -530,6 +539,9 @@ mod prim_i32 { }
530539
///
531540
/// *[See also the `std::i64` module](i64/index.html).*
532541
///
542+
/// However, please note that examples are shared between primitive integer
543+
/// types. So it's normal if you see usage of types like `i8` in there.
544+
///
533545
mod prim_i64 { }
534546

535547
#[doc(primitive = "u8")]
@@ -538,6 +550,9 @@ mod prim_i64 { }
538550
///
539551
/// *[See also the `std::u8` module](u8/index.html).*
540552
///
553+
/// However, please note that examples are shared between primitive integer
554+
/// types. So it's normal if you see usage of types like `u64` in there.
555+
///
541556
mod prim_u8 { }
542557

543558
#[doc(primitive = "u16")]
@@ -546,6 +561,9 @@ mod prim_u8 { }
546561
///
547562
/// *[See also the `std::u16` module](u16/index.html).*
548563
///
564+
/// However, please note that examples are shared between primitive integer
565+
/// types. So it's normal if you see usage of types like `u32` in there.
566+
///
549567
mod prim_u16 { }
550568

551569
#[doc(primitive = "u32")]
@@ -554,6 +572,9 @@ mod prim_u16 { }
554572
///
555573
/// *[See also the `std::u32` module](u32/index.html).*
556574
///
575+
/// However, please note that examples are shared between primitive integer
576+
/// types. So it's normal if you see usage of types like `u16` in there.
577+
///
557578
mod prim_u32 { }
558579

559580
#[doc(primitive = "u64")]
@@ -562,6 +583,9 @@ mod prim_u32 { }
562583
///
563584
/// *[See also the `std::u64` module](u64/index.html).*
564585
///
586+
/// However, please note that examples are shared between primitive integer
587+
/// types. So it's normal if you see usage of types like `u8` in there.
588+
///
565589
mod prim_u64 { }
566590

567591
#[doc(primitive = "isize")]
@@ -570,6 +594,9 @@ mod prim_u64 { }
570594
///
571595
/// *[See also the `std::isize` module](isize/index.html).*
572596
///
597+
/// However, please note that examples are shared between primitive integer
598+
/// types. So it's normal if you see usage of types like `usize` in there.
599+
///
573600
mod prim_isize { }
574601

575602
#[doc(primitive = "usize")]
@@ -578,4 +605,7 @@ mod prim_isize { }
578605
///
579606
/// *[See also the `std::usize` module](usize/index.html).*
580607
///
608+
/// However, please note that examples are shared between primitive integer
609+
/// types. So it's normal if you see usage of types like `isize` in there.
610+
///
581611
mod prim_usize { }

0 commit comments

Comments
 (0)