@@ -78,6 +78,12 @@ pub trait Add<Rhs = Self> {
7878 type Output;
7979
8080 /// Performs the `+` operation.
81+ ///
82+ /// # Example
83+ ///
84+ /// ```
85+ /// assert_eq!(12 + 1, 13);
86+ /// ```
8187 #[must_use]
8288 #[stable(feature = "rust1", since = "1.0.0")]
8389 fn add(self, rhs: Rhs) -> Self::Output;
@@ -178,6 +184,12 @@ pub trait Sub<Rhs = Self> {
178184 type Output;
179185
180186 /// Performs the `-` operation.
187+ ///
188+ /// # Example
189+ ///
190+ /// ```
191+ /// assert_eq!(12 - 1, 11);
192+ /// ```
181193 #[must_use]
182194 #[stable(feature = "rust1", since = "1.0.0")]
183195 fn sub(self, rhs: Rhs) -> Self::Output;
@@ -300,6 +312,12 @@ pub trait Mul<Rhs = Self> {
300312 type Output;
301313
302314 /// Performs the `*` operation.
315+ ///
316+ /// # Example
317+ ///
318+ /// ```
319+ /// assert_eq!(12 * 2, 24);
320+ /// ```
303321 #[must_use]
304322 #[stable(feature = "rust1", since = "1.0.0")]
305323 fn mul(self, rhs: Rhs) -> Self::Output;
@@ -426,6 +444,12 @@ pub trait Div<Rhs = Self> {
426444 type Output;
427445
428446 /// Performs the `/` operation.
447+ ///
448+ /// # Example
449+ ///
450+ /// ```
451+ /// assert_eq!(12 / 2, 6);
452+ /// ```
429453 #[must_use]
430454 #[stable(feature = "rust1", since = "1.0.0")]
431455 fn div(self, rhs: Rhs) -> Self::Output;
@@ -513,6 +537,12 @@ pub trait Rem<Rhs = Self> {
513537 type Output;
514538
515539 /// Performs the `%` operation.
540+ ///
541+ /// # Example
542+ ///
543+ /// ```
544+ /// assert_eq!(12 % 10, 2);
545+ /// ```
516546 #[must_use]
517547 #[stable(feature = "rust1", since = "1.0.0")]
518548 fn rem(self, rhs: Rhs) -> Self::Output;
@@ -612,6 +642,13 @@ pub trait Neg {
612642 type Output;
613643
614644 /// Performs the unary `-` operation.
645+ ///
646+ /// # Example
647+ ///
648+ /// ```
649+ /// let x: i32 = 12;
650+ /// assert_eq!(-x, -12);
651+ /// ```
615652 #[must_use]
616653 #[stable(feature = "rust1", since = "1.0.0")]
617654 fn neg(self) -> Self::Output;
@@ -673,6 +710,14 @@ neg_impl! { isize i8 i16 i32 i64 i128 f32 f64 }
673710#[doc(alias = "+=")]
674711pub trait AddAssign<Rhs = Self> {
675712 /// Performs the `+=` operation.
713+ ///
714+ /// # Example
715+ ///
716+ /// ```
717+ /// let mut x: u32 = 12;
718+ /// x += 1;
719+ /// assert_eq!(x, 13);
720+ /// ```
676721 #[stable(feature = "op_assign_traits", since = "1.8.0")]
677722 fn add_assign(&mut self, rhs: Rhs);
678723}
@@ -731,6 +776,14 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
731776#[doc(alias = "-=")]
732777pub trait SubAssign<Rhs = Self> {
733778 /// Performs the `-=` operation.
779+ ///
780+ /// # Example
781+ ///
782+ /// ```
783+ /// let mut x: u32 = 12;
784+ /// x -= 1;
785+ /// assert_eq!(x, 11);
786+ /// ```
734787 #[stable(feature = "op_assign_traits", since = "1.8.0")]
735788 fn sub_assign(&mut self, rhs: Rhs);
736789}
@@ -780,6 +833,14 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
780833#[doc(alias = "*=")]
781834pub trait MulAssign<Rhs = Self> {
782835 /// Performs the `*=` operation.
836+ ///
837+ /// # Example
838+ ///
839+ /// ```
840+ /// let mut x: u32 = 12;
841+ /// x *= 2;
842+ /// assert_eq!(x, 24);
843+ /// ```
783844 #[stable(feature = "op_assign_traits", since = "1.8.0")]
784845 fn mul_assign(&mut self, rhs: Rhs);
785846}
@@ -829,6 +890,14 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
829890#[doc(alias = "/=")]
830891pub trait DivAssign<Rhs = Self> {
831892 /// Performs the `/=` operation.
893+ ///
894+ /// # Example
895+ ///
896+ /// ```
897+ /// let mut x: u32 = 12;
898+ /// x /= 2;
899+ /// assert_eq!(x, 6);
900+ /// ```
832901 #[stable(feature = "op_assign_traits", since = "1.8.0")]
833902 fn div_assign(&mut self, rhs: Rhs);
834903}
@@ -881,6 +950,14 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
881950#[doc(alias = "%=")]
882951pub trait RemAssign<Rhs = Self> {
883952 /// Performs the `%=` operation.
953+ ///
954+ /// # Example
955+ ///
956+ /// ```
957+ /// let mut x: u32 = 12;
958+ /// x %= 10;
959+ /// assert_eq!(x, 2);
960+ /// ```
884961 #[stable(feature = "op_assign_traits", since = "1.8.0")]
885962 fn rem_assign(&mut self, rhs: Rhs);
886963}
0 commit comments