@@ -36,6 +36,15 @@ pub trait Not {
36
36
type Output ;
37
37
38
38
/// Performs the unary `!` operation.
39
+ ///
40
+ /// # Examples
41
+ ///
42
+ /// ```
43
+ /// assert_eq!(!true, false);
44
+ /// assert_eq!(!false, true);
45
+ /// assert_eq!(!1u8, 254);
46
+ /// assert_eq!(!0u8, 255);
47
+ /// ```
39
48
#[ must_use]
40
49
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
41
50
fn not ( self ) -> Self :: Output ;
@@ -122,6 +131,15 @@ pub trait BitAnd<Rhs = Self> {
122
131
type Output ;
123
132
124
133
/// Performs the `&` operation.
134
+ ///
135
+ /// # Examples
136
+ ///
137
+ /// ```
138
+ /// assert_eq!(true & false, false);
139
+ /// assert_eq!(true & true, true);
140
+ /// assert_eq!(5u8 & 1u8, 1);
141
+ /// assert_eq!(5u8 & 2u8, 0);
142
+ /// ```
125
143
#[ must_use]
126
144
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
127
145
fn bitand ( self , rhs : Rhs ) -> Self :: Output ;
@@ -208,6 +226,15 @@ pub trait BitOr<Rhs = Self> {
208
226
type Output ;
209
227
210
228
/// Performs the `|` operation.
229
+ ///
230
+ /// # Examples
231
+ ///
232
+ /// ```
233
+ /// assert_eq!(true | false, true);
234
+ /// assert_eq!(false | false, false);
235
+ /// assert_eq!(5u8 | 1u8, 5);
236
+ /// assert_eq!(5u8 | 2u8, 7);
237
+ /// ```
211
238
#[ must_use]
212
239
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
213
240
fn bitor ( self , rhs : Rhs ) -> Self :: Output ;
@@ -297,6 +324,15 @@ pub trait BitXor<Rhs = Self> {
297
324
type Output ;
298
325
299
326
/// Performs the `^` operation.
327
+ ///
328
+ /// # Examples
329
+ ///
330
+ /// ```
331
+ /// assert_eq!(true ^ false, true);
332
+ /// assert_eq!(true ^ true, false);
333
+ /// assert_eq!(5u8 ^ 1u8, 4);
334
+ /// assert_eq!(5u8 ^ 2u8, 7);
335
+ /// ```
300
336
#[ must_use]
301
337
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
302
338
fn bitxor ( self , rhs : Rhs ) -> Self :: Output ;
@@ -387,6 +423,13 @@ pub trait Shl<Rhs = Self> {
387
423
type Output ;
388
424
389
425
/// Performs the `<<` operation.
426
+ ///
427
+ /// # Examples
428
+ ///
429
+ /// ```
430
+ /// assert_eq!(5u8 << 1, 10);
431
+ /// assert_eq!(1u8 << 1, 2);
432
+ /// ```
390
433
#[ must_use]
391
434
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
392
435
fn shl ( self , rhs : Rhs ) -> Self :: Output ;
@@ -498,6 +541,13 @@ pub trait Shr<Rhs = Self> {
498
541
type Output ;
499
542
500
543
/// Performs the `>>` operation.
544
+ ///
545
+ /// # Examples
546
+ ///
547
+ /// ```
548
+ /// assert_eq!(5u8 >> 1, 2);
549
+ /// assert_eq!(2u8 >> 1, 1);
550
+ /// ```
501
551
#[ must_use]
502
552
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
503
553
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 }
612
662
) ]
613
663
pub trait BitAndAssign < Rhs = Self > {
614
664
/// Performs the `&=` operation.
665
+ ///
666
+ /// # Examples
667
+ ///
668
+ /// ```
669
+ /// let mut x = true;
670
+ /// x &= false;
671
+ /// assert_eq!(x, false);
672
+ ///
673
+ /// let mut x = true;
674
+ /// x &= true;
675
+ /// assert_eq!(x, true);
676
+ ///
677
+ /// let mut x: u8 = 5;
678
+ /// x &= 1;
679
+ /// assert_eq!(x, 1);
680
+ ///
681
+ /// let mut x: u8 = 5;
682
+ /// x &= 2;
683
+ /// assert_eq!(x, 0);
684
+ /// ```
615
685
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
616
686
fn bitand_assign ( & mut self , rhs : Rhs ) ;
617
687
}
@@ -663,6 +733,26 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
663
733
) ]
664
734
pub trait BitOrAssign < Rhs = Self > {
665
735
/// Performs the `|=` operation.
736
+ ///
737
+ /// # Examples
738
+ ///
739
+ /// ```
740
+ /// let mut x = true;
741
+ /// x |= false;
742
+ /// assert_eq!(x, true);
743
+ ///
744
+ /// let mut x = false;
745
+ /// x |= false;
746
+ /// assert_eq!(x, false);
747
+ ///
748
+ /// let mut x: u8 = 5;
749
+ /// x |= 1;
750
+ /// assert_eq!(x, 5);
751
+ ///
752
+ /// let mut x: u8 = 5;
753
+ /// x |= 2;
754
+ /// assert_eq!(x, 7);
755
+ /// ```
666
756
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
667
757
fn bitor_assign ( & mut self , rhs : Rhs ) ;
668
758
}
@@ -714,6 +804,26 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
714
804
) ]
715
805
pub trait BitXorAssign < Rhs = Self > {
716
806
/// Performs the `^=` operation.
807
+ ///
808
+ /// # Examples
809
+ ///
810
+ /// ```
811
+ /// let mut x = true;
812
+ /// x ^= false;
813
+ /// assert_eq!(x, true);
814
+ ///
815
+ /// let mut x = true;
816
+ /// x ^= true;
817
+ /// assert_eq!(x, false);
818
+ ///
819
+ /// let mut x: u8 = 5;
820
+ /// x ^= 1;
821
+ /// assert_eq!(x, 4);
822
+ ///
823
+ /// let mut x: u8 = 5;
824
+ /// x ^= 2;
825
+ /// assert_eq!(x, 7);
826
+ /// ```
717
827
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
718
828
fn bitxor_assign ( & mut self , rhs : Rhs ) ;
719
829
}
@@ -763,6 +873,18 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
763
873
) ]
764
874
pub trait ShlAssign < Rhs = Self > {
765
875
/// Performs the `<<=` operation.
876
+ ///
877
+ /// # Examples
878
+ ///
879
+ /// ```
880
+ /// let mut x: u8 = 5;
881
+ /// x <<= 1;
882
+ /// assert_eq!(x, 10);
883
+ ///
884
+ /// let mut x: u8 = 1;
885
+ /// x <<= 1;
886
+ /// assert_eq!(x, 2);
887
+ /// ```
766
888
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
767
889
fn shl_assign ( & mut self , rhs : Rhs ) ;
768
890
}
@@ -833,6 +955,18 @@ shl_assign_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
833
955
) ]
834
956
pub trait ShrAssign < Rhs = Self > {
835
957
/// Performs the `>>=` operation.
958
+ ///
959
+ /// # Examples
960
+ ///
961
+ /// ```
962
+ /// let mut x: u8 = 5;
963
+ /// x >>= 1;
964
+ /// assert_eq!(x, 2);
965
+ ///
966
+ /// let mut x: u8 = 2;
967
+ /// x >>= 1;
968
+ /// assert_eq!(x, 1);
969
+ /// ```
836
970
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
837
971
fn shr_assign ( & mut self , rhs : Rhs ) ;
838
972
}
0 commit comments