Skip to content

Improve primitive integers documentation #34709

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

Merged
merged 1 commit into from
Jul 9, 2016
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
32 changes: 32 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,25 @@ macro_rules! int_impl {
$sub_with_overflow:path,
$mul_with_overflow:path) => {
/// Returns the smallest value that can be represented by this integer type.
///
/// # Examples
///
/// ```
/// assert_eq!(i8::min_value(), -128);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub const fn min_value() -> Self {
(-1 as Self) << ($BITS - 1)
}

/// Returns the largest value that can be represented by this integer type.
///
/// # Examples
///
/// ```
/// assert_eq!(i8::max_value(), 127);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub const fn max_value() -> Self {
Expand Down Expand Up @@ -287,6 +299,8 @@ macro_rules! int_impl {
/// Shifts the bits to the left by a specified amount, `n`,
/// wrapping the truncated bits to the end of the resulting integer.
///
/// Please note this isn't the same operation as `<<`!
///
/// # Examples
///
/// Basic usage:
Expand All @@ -307,6 +321,8 @@ macro_rules! int_impl {
/// wrapping the truncated bits to the beginning of the resulting
/// integer.
///
/// Please note this isn't the same operation as `>>`!
///
/// # Examples
///
/// Basic usage:
Expand Down Expand Up @@ -1249,11 +1265,23 @@ macro_rules! uint_impl {
$sub_with_overflow:path,
$mul_with_overflow:path) => {
/// Returns the smallest value that can be represented by this integer type.
///
/// # Examples
///
/// ```
/// assert_eq!(u8::min_value(), 0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub const fn min_value() -> Self { 0 }

/// Returns the largest value that can be represented by this integer type.
///
/// # Examples
///
/// ```
/// assert_eq!(u8::max_value(), 255);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub const fn max_value() -> Self { !0 }
Expand Down Expand Up @@ -1360,6 +1388,8 @@ macro_rules! uint_impl {
/// Shifts the bits to the left by a specified amount, `n`,
/// wrapping the truncated bits to the end of the resulting integer.
///
/// Please note this isn't the same operation as `<<`!
///
/// # Examples
///
/// Basic usage:
Expand All @@ -1382,6 +1412,8 @@ macro_rules! uint_impl {
/// wrapping the truncated bits to the beginning of the resulting
/// integer.
///
/// Please note this isn't the same operation as `>>`!
///
/// # Examples
///
/// Basic usage:
Expand Down
30 changes: 30 additions & 0 deletions src/libstd/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ mod prim_f64 { }
///
/// *[See also the `std::i8` module](i8/index.html).*
///
/// However, please note that examples are shared between primitive integer
/// types. So it's normal if you see usage of types like `i64` in there.
///
mod prim_i8 { }

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

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

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

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

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

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

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

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

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