Rollup merge of #76615 - GuillaumeGomez:missing-examples-binary-ops, r=jyn514

Add missing examples on binary core traits

r? @jyn514
This commit is contained in:
Ralf Jung 2020-09-12 10:43:24 +02:00 committed by GitHub
commit 0ed4bc5993
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,15 @@ pub trait Not {
type Output;
/// Performs the unary `!` operation.
///
/// # Examples
///
/// ```
/// assert_eq!(!true, false);
/// assert_eq!(!false, true);
/// assert_eq!(!1u8, 254);
/// assert_eq!(!0u8, 255);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn not(self) -> Self::Output;
@ -122,6 +131,15 @@ pub trait BitAnd<Rhs = Self> {
type Output;
/// Performs the `&` operation.
///
/// # Examples
///
/// ```
/// assert_eq!(true & false, false);
/// assert_eq!(true & true, true);
/// assert_eq!(5u8 & 1u8, 1);
/// assert_eq!(5u8 & 2u8, 0);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn bitand(self, rhs: Rhs) -> Self::Output;
@ -208,6 +226,15 @@ pub trait BitOr<Rhs = Self> {
type Output;
/// Performs the `|` operation.
///
/// # Examples
///
/// ```
/// assert_eq!(true | false, true);
/// assert_eq!(false | false, false);
/// assert_eq!(5u8 | 1u8, 5);
/// assert_eq!(5u8 | 2u8, 7);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn bitor(self, rhs: Rhs) -> Self::Output;
@ -297,6 +324,15 @@ pub trait BitXor<Rhs = Self> {
type Output;
/// Performs the `^` operation.
///
/// # Examples
///
/// ```
/// assert_eq!(true ^ false, true);
/// assert_eq!(true ^ true, false);
/// assert_eq!(5u8 ^ 1u8, 4);
/// assert_eq!(5u8 ^ 2u8, 7);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn bitxor(self, rhs: Rhs) -> Self::Output;
@ -387,6 +423,13 @@ pub trait Shl<Rhs = Self> {
type Output;
/// Performs the `<<` operation.
///
/// # Examples
///
/// ```
/// assert_eq!(5u8 << 1, 10);
/// assert_eq!(1u8 << 1, 2);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn shl(self, rhs: Rhs) -> Self::Output;
@ -498,6 +541,13 @@ pub trait Shr<Rhs = Self> {
type Output;
/// Performs the `>>` operation.
///
/// # Examples
///
/// ```
/// assert_eq!(5u8 >> 1, 2);
/// assert_eq!(2u8 >> 1, 1);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn shr(self, rhs: Rhs) -> Self::Output;
@ -612,6 +662,26 @@ shr_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
)]
pub trait BitAndAssign<Rhs = Self> {
/// Performs the `&=` operation.
///
/// # Examples
///
/// ```
/// let mut x = true;
/// x &= false;
/// assert_eq!(x, false);
///
/// let mut x = true;
/// x &= true;
/// assert_eq!(x, true);
///
/// let mut x: u8 = 5;
/// x &= 1;
/// assert_eq!(x, 1);
///
/// let mut x: u8 = 5;
/// x &= 2;
/// assert_eq!(x, 0);
/// ```
#[stable(feature = "op_assign_traits", since = "1.8.0")]
fn bitand_assign(&mut self, rhs: Rhs);
}
@ -663,6 +733,26 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
)]
pub trait BitOrAssign<Rhs = Self> {
/// Performs the `|=` operation.
///
/// # Examples
///
/// ```
/// let mut x = true;
/// x |= false;
/// assert_eq!(x, true);
///
/// let mut x = false;
/// x |= false;
/// assert_eq!(x, false);
///
/// let mut x: u8 = 5;
/// x |= 1;
/// assert_eq!(x, 5);
///
/// let mut x: u8 = 5;
/// x |= 2;
/// assert_eq!(x, 7);
/// ```
#[stable(feature = "op_assign_traits", since = "1.8.0")]
fn bitor_assign(&mut self, rhs: Rhs);
}
@ -714,6 +804,26 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
)]
pub trait BitXorAssign<Rhs = Self> {
/// Performs the `^=` operation.
///
/// # Examples
///
/// ```
/// let mut x = true;
/// x ^= false;
/// assert_eq!(x, true);
///
/// let mut x = true;
/// x ^= true;
/// assert_eq!(x, false);
///
/// let mut x: u8 = 5;
/// x ^= 1;
/// assert_eq!(x, 4);
///
/// let mut x: u8 = 5;
/// x ^= 2;
/// assert_eq!(x, 7);
/// ```
#[stable(feature = "op_assign_traits", since = "1.8.0")]
fn bitxor_assign(&mut self, rhs: Rhs);
}
@ -763,6 +873,18 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
)]
pub trait ShlAssign<Rhs = Self> {
/// Performs the `<<=` operation.
///
/// # Examples
///
/// ```
/// let mut x: u8 = 5;
/// x <<= 1;
/// assert_eq!(x, 10);
///
/// let mut x: u8 = 1;
/// x <<= 1;
/// assert_eq!(x, 2);
/// ```
#[stable(feature = "op_assign_traits", since = "1.8.0")]
fn shl_assign(&mut self, rhs: Rhs);
}
@ -833,6 +955,18 @@ shl_assign_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
)]
pub trait ShrAssign<Rhs = Self> {
/// Performs the `>>=` operation.
///
/// # Examples
///
/// ```
/// let mut x: u8 = 5;
/// x >>= 1;
/// assert_eq!(x, 2);
///
/// let mut x: u8 = 2;
/// x >>= 1;
/// assert_eq!(x, 1);
/// ```
#[stable(feature = "op_assign_traits", since = "1.8.0")]
fn shr_assign(&mut self, rhs: Rhs);
}