@@ -78,6 +78,12 @@ pub trait Add<Rhs = Self> {
78
78
type Output ;
79
79
80
80
/// Performs the `+` operation.
81
+ ///
82
+ /// # Example
83
+ ///
84
+ /// ```
85
+ /// assert_eq!(12 + 1, 13);
86
+ /// ```
81
87
#[ must_use]
82
88
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
83
89
fn add ( self , rhs : Rhs ) -> Self :: Output ;
@@ -178,6 +184,12 @@ pub trait Sub<Rhs = Self> {
178
184
type Output ;
179
185
180
186
/// Performs the `-` operation.
187
+ ///
188
+ /// # Example
189
+ ///
190
+ /// ```
191
+ /// assert_eq!(12 - 1, 11);
192
+ /// ```
181
193
#[ must_use]
182
194
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
183
195
fn sub ( self , rhs : Rhs ) -> Self :: Output ;
@@ -300,6 +312,12 @@ pub trait Mul<Rhs = Self> {
300
312
type Output ;
301
313
302
314
/// Performs the `*` operation.
315
+ ///
316
+ /// # Example
317
+ ///
318
+ /// ```
319
+ /// assert_eq!(12 * 2, 24);
320
+ /// ```
303
321
#[ must_use]
304
322
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
305
323
fn mul ( self , rhs : Rhs ) -> Self :: Output ;
@@ -426,6 +444,12 @@ pub trait Div<Rhs = Self> {
426
444
type Output ;
427
445
428
446
/// Performs the `/` operation.
447
+ ///
448
+ /// # Example
449
+ ///
450
+ /// ```
451
+ /// assert_eq!(12 / 2, 6);
452
+ /// ```
429
453
#[ must_use]
430
454
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
431
455
fn div ( self , rhs : Rhs ) -> Self :: Output ;
@@ -513,6 +537,12 @@ pub trait Rem<Rhs = Self> {
513
537
type Output ;
514
538
515
539
/// Performs the `%` operation.
540
+ ///
541
+ /// # Example
542
+ ///
543
+ /// ```
544
+ /// assert_eq!(12 % 10, 2);
545
+ /// ```
516
546
#[ must_use]
517
547
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
518
548
fn rem ( self , rhs : Rhs ) -> Self :: Output ;
@@ -612,6 +642,13 @@ pub trait Neg {
612
642
type Output ;
613
643
614
644
/// Performs the unary `-` operation.
645
+ ///
646
+ /// # Example
647
+ ///
648
+ /// ```
649
+ /// let x: i32 = 12;
650
+ /// assert_eq!(-x, -12);
651
+ /// ```
615
652
#[ must_use]
616
653
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
617
654
fn neg ( self ) -> Self :: Output ;
@@ -673,6 +710,14 @@ neg_impl! { isize i8 i16 i32 i64 i128 f32 f64 }
673
710
#[ doc( alias = "+=" ) ]
674
711
pub trait AddAssign < Rhs = Self > {
675
712
/// Performs the `+=` operation.
713
+ ///
714
+ /// # Example
715
+ ///
716
+ /// ```
717
+ /// let mut x: u32 = 12;
718
+ /// x += 1;
719
+ /// assert_eq!(x, 13);
720
+ /// ```
676
721
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
677
722
fn add_assign ( & mut self , rhs : Rhs ) ;
678
723
}
@@ -731,6 +776,14 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
731
776
#[ doc( alias = "-=" ) ]
732
777
pub trait SubAssign < Rhs = Self > {
733
778
/// Performs the `-=` operation.
779
+ ///
780
+ /// # Example
781
+ ///
782
+ /// ```
783
+ /// let mut x: u32 = 12;
784
+ /// x -= 1;
785
+ /// assert_eq!(x, 11);
786
+ /// ```
734
787
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
735
788
fn sub_assign ( & mut self , rhs : Rhs ) ;
736
789
}
@@ -780,6 +833,14 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
780
833
#[ doc( alias = "*=" ) ]
781
834
pub trait MulAssign < Rhs = Self > {
782
835
/// Performs the `*=` operation.
836
+ ///
837
+ /// # Example
838
+ ///
839
+ /// ```
840
+ /// let mut x: u32 = 12;
841
+ /// x *= 2;
842
+ /// assert_eq!(x, 24);
843
+ /// ```
783
844
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
784
845
fn mul_assign ( & mut self , rhs : Rhs ) ;
785
846
}
@@ -829,6 +890,14 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
829
890
#[ doc( alias = "/=" ) ]
830
891
pub trait DivAssign < Rhs = Self > {
831
892
/// Performs the `/=` operation.
893
+ ///
894
+ /// # Example
895
+ ///
896
+ /// ```
897
+ /// let mut x: u32 = 12;
898
+ /// x /= 2;
899
+ /// assert_eq!(x, 6);
900
+ /// ```
832
901
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
833
902
fn div_assign ( & mut self , rhs : Rhs ) ;
834
903
}
@@ -881,6 +950,14 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
881
950
#[ doc( alias = "%=" ) ]
882
951
pub trait RemAssign < Rhs = Self > {
883
952
/// Performs the `%=` operation.
953
+ ///
954
+ /// # Example
955
+ ///
956
+ /// ```
957
+ /// let mut x: u32 = 12;
958
+ /// x %= 10;
959
+ /// assert_eq!(x, 2);
960
+ /// ```
884
961
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
885
962
fn rem_assign ( & mut self , rhs : Rhs ) ;
886
963
}
0 commit comments