Add missing examples on binary core traits
This commit is contained in:
parent
02fe30971e
commit
bb9ce7cb01
@ -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 @@ macro_rules! shr_impl_all {
|
||||
)]
|
||||
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 @@ fn bitand_assign(&mut self, other: $t) { *self &= other }
|
||||
)]
|
||||
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 @@ fn bitor_assign(&mut self, other: $t) { *self |= other }
|
||||
)]
|
||||
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 @@ fn bitxor_assign(&mut self, other: $t) { *self ^= other }
|
||||
)]
|
||||
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 @@ macro_rules! shl_assign_impl_all {
|
||||
)]
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user