1 /// The unary logical negation operator `!`.
5 /// An implementation of `Not` for `Answer`, which enables the use of `!` to
11 /// #[derive(Debug, PartialEq)]
17 /// impl Not for Answer {
18 /// type Output = Self;
20 /// fn not(self) -> Self::Output {
22 /// Answer::Yes => Answer::No,
23 /// Answer::No => Answer::Yes
28 /// assert_eq!(!Answer::Yes, Answer::No);
29 /// assert_eq!(!Answer::No, Answer::Yes);
32 #[stable(feature = "rust1", since = "1.0.0")]
35 /// The resulting type after applying the `!` operator.
36 #[stable(feature = "rust1", since = "1.0.0")]
39 /// Performs the unary `!` operation.
44 /// assert_eq!(!true, false);
45 /// assert_eq!(!false, true);
46 /// assert_eq!(!1u8, 254);
47 /// assert_eq!(!0u8, 255);
50 #[stable(feature = "rust1", since = "1.0.0")]
51 fn not(self) -> Self::Output
;
54 macro_rules
! not_impl
{
56 #[stable(feature = "rust1", since = "1.0.0")]
61 fn not(self) -> $t { !self }
64 forward_ref_unop
! { impl Not, not for $t }
68 not_impl
! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
70 #[stable(feature = "not_never", since = "1.60.0")]
80 /// The bitwise AND operator `&`.
82 /// Note that `Rhs` is `Self` by default, but this is not mandatory.
86 /// An implementation of `BitAnd` for a wrapper around `bool`.
89 /// use std::ops::BitAnd;
91 /// #[derive(Debug, PartialEq)]
92 /// struct Scalar(bool);
94 /// impl BitAnd for Scalar {
95 /// type Output = Self;
97 /// // rhs is the "right-hand side" of the expression `a & b`
98 /// fn bitand(self, rhs: Self) -> Self::Output {
99 /// Self(self.0 & rhs.0)
103 /// assert_eq!(Scalar(true) & Scalar(true), Scalar(true));
104 /// assert_eq!(Scalar(true) & Scalar(false), Scalar(false));
105 /// assert_eq!(Scalar(false) & Scalar(true), Scalar(false));
106 /// assert_eq!(Scalar(false) & Scalar(false), Scalar(false));
109 /// An implementation of `BitAnd` for a wrapper around `Vec<bool>`.
112 /// use std::ops::BitAnd;
114 /// #[derive(Debug, PartialEq)]
115 /// struct BooleanVector(Vec<bool>);
117 /// impl BitAnd for BooleanVector {
118 /// type Output = Self;
120 /// fn bitand(self, Self(rhs): Self) -> Self::Output {
121 /// let Self(lhs) = self;
122 /// assert_eq!(lhs.len(), rhs.len());
126 /// .map(|(x, y)| *x & *y)
132 /// let bv1 = BooleanVector(vec![true, true, false, false]);
133 /// let bv2 = BooleanVector(vec![true, false, true, false]);
134 /// let expected = BooleanVector(vec![true, false, false, false]);
135 /// assert_eq!(bv1 & bv2, expected);
139 #[stable(feature = "rust1", since = "1.0.0")]
140 #[rustc_on_unimplemented(
141 message
= "no implementation for `{Self} & {Rhs}`",
142 label
= "no implementation for `{Self} & {Rhs}`"
144 pub trait BitAnd
<Rhs
= Self> {
145 /// The resulting type after applying the `&` operator.
146 #[stable(feature = "rust1", since = "1.0.0")]
149 /// Performs the `&` operation.
154 /// assert_eq!(true & false, false);
155 /// assert_eq!(true & true, true);
156 /// assert_eq!(5u8 & 1u8, 1);
157 /// assert_eq!(5u8 & 2u8, 0);
160 #[stable(feature = "rust1", since = "1.0.0")]
161 fn bitand(self, rhs
: Rhs
) -> Self::Output
;
164 macro_rules
! bitand_impl
{
166 #[stable(feature = "rust1", since = "1.0.0")]
171 fn bitand(self, rhs
: $t
) -> $t { self & rhs }
174 forward_ref_binop
! { impl BitAnd, bitand for $t, $t }
178 bitand_impl
! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
180 /// The bitwise OR operator `|`.
182 /// Note that `Rhs` is `Self` by default, but this is not mandatory.
186 /// An implementation of `BitOr` for a wrapper around `bool`.
189 /// use std::ops::BitOr;
191 /// #[derive(Debug, PartialEq)]
192 /// struct Scalar(bool);
194 /// impl BitOr for Scalar {
195 /// type Output = Self;
197 /// // rhs is the "right-hand side" of the expression `a | b`
198 /// fn bitor(self, rhs: Self) -> Self::Output {
199 /// Self(self.0 | rhs.0)
203 /// assert_eq!(Scalar(true) | Scalar(true), Scalar(true));
204 /// assert_eq!(Scalar(true) | Scalar(false), Scalar(true));
205 /// assert_eq!(Scalar(false) | Scalar(true), Scalar(true));
206 /// assert_eq!(Scalar(false) | Scalar(false), Scalar(false));
209 /// An implementation of `BitOr` for a wrapper around `Vec<bool>`.
212 /// use std::ops::BitOr;
214 /// #[derive(Debug, PartialEq)]
215 /// struct BooleanVector(Vec<bool>);
217 /// impl BitOr for BooleanVector {
218 /// type Output = Self;
220 /// fn bitor(self, Self(rhs): Self) -> Self::Output {
221 /// let Self(lhs) = self;
222 /// assert_eq!(lhs.len(), rhs.len());
226 /// .map(|(x, y)| *x | *y)
232 /// let bv1 = BooleanVector(vec![true, true, false, false]);
233 /// let bv2 = BooleanVector(vec![true, false, true, false]);
234 /// let expected = BooleanVector(vec![true, true, true, false]);
235 /// assert_eq!(bv1 | bv2, expected);
239 #[stable(feature = "rust1", since = "1.0.0")]
240 #[rustc_on_unimplemented(
241 message
= "no implementation for `{Self} | {Rhs}`",
242 label
= "no implementation for `{Self} | {Rhs}`"
244 pub trait BitOr
<Rhs
= Self> {
245 /// The resulting type after applying the `|` operator.
246 #[stable(feature = "rust1", since = "1.0.0")]
249 /// Performs the `|` operation.
254 /// assert_eq!(true | false, true);
255 /// assert_eq!(false | false, false);
256 /// assert_eq!(5u8 | 1u8, 5);
257 /// assert_eq!(5u8 | 2u8, 7);
260 #[stable(feature = "rust1", since = "1.0.0")]
261 fn bitor(self, rhs
: Rhs
) -> Self::Output
;
264 macro_rules
! bitor_impl
{
266 #[stable(feature = "rust1", since = "1.0.0")]
271 fn bitor(self, rhs
: $t
) -> $t { self | rhs }
274 forward_ref_binop
! { impl BitOr, bitor for $t, $t }
278 bitor_impl
! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
280 /// The bitwise XOR operator `^`.
282 /// Note that `Rhs` is `Self` by default, but this is not mandatory.
286 /// An implementation of `BitXor` that lifts `^` to a wrapper around `bool`.
289 /// use std::ops::BitXor;
291 /// #[derive(Debug, PartialEq)]
292 /// struct Scalar(bool);
294 /// impl BitXor for Scalar {
295 /// type Output = Self;
297 /// // rhs is the "right-hand side" of the expression `a ^ b`
298 /// fn bitxor(self, rhs: Self) -> Self::Output {
299 /// Self(self.0 ^ rhs.0)
303 /// assert_eq!(Scalar(true) ^ Scalar(true), Scalar(false));
304 /// assert_eq!(Scalar(true) ^ Scalar(false), Scalar(true));
305 /// assert_eq!(Scalar(false) ^ Scalar(true), Scalar(true));
306 /// assert_eq!(Scalar(false) ^ Scalar(false), Scalar(false));
309 /// An implementation of `BitXor` trait for a wrapper around `Vec<bool>`.
312 /// use std::ops::BitXor;
314 /// #[derive(Debug, PartialEq)]
315 /// struct BooleanVector(Vec<bool>);
317 /// impl BitXor for BooleanVector {
318 /// type Output = Self;
320 /// fn bitxor(self, Self(rhs): Self) -> Self::Output {
321 /// let Self(lhs) = self;
322 /// assert_eq!(lhs.len(), rhs.len());
326 /// .map(|(x, y)| *x ^ *y)
332 /// let bv1 = BooleanVector(vec![true, true, false, false]);
333 /// let bv2 = BooleanVector(vec![true, false, true, false]);
334 /// let expected = BooleanVector(vec![false, true, true, false]);
335 /// assert_eq!(bv1 ^ bv2, expected);
339 #[stable(feature = "rust1", since = "1.0.0")]
340 #[rustc_on_unimplemented(
341 message
= "no implementation for `{Self} ^ {Rhs}`",
342 label
= "no implementation for `{Self} ^ {Rhs}`"
344 pub trait BitXor
<Rhs
= Self> {
345 /// The resulting type after applying the `^` operator.
346 #[stable(feature = "rust1", since = "1.0.0")]
349 /// Performs the `^` operation.
354 /// assert_eq!(true ^ false, true);
355 /// assert_eq!(true ^ true, false);
356 /// assert_eq!(5u8 ^ 1u8, 4);
357 /// assert_eq!(5u8 ^ 2u8, 7);
360 #[stable(feature = "rust1", since = "1.0.0")]
361 fn bitxor(self, rhs
: Rhs
) -> Self::Output
;
364 macro_rules
! bitxor_impl
{
366 #[stable(feature = "rust1", since = "1.0.0")]
371 fn bitxor(self, other
: $t
) -> $t { self ^ other }
374 forward_ref_binop
! { impl BitXor, bitxor for $t, $t }
378 bitxor_impl
! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
380 /// The left shift operator `<<`. Note that because this trait is implemented
381 /// for all integer types with multiple right-hand-side types, Rust's type
382 /// checker has special handling for `_ << _`, setting the result type for
383 /// integer operations to the type of the left-hand-side operand. This means
384 /// that though `a << b` and `a.shl(b)` are one and the same from an evaluation
385 /// standpoint, they are different when it comes to type inference.
389 /// An implementation of `Shl` that lifts the `<<` operation on integers to a
390 /// wrapper around `usize`.
393 /// use std::ops::Shl;
395 /// #[derive(PartialEq, Debug)]
396 /// struct Scalar(usize);
398 /// impl Shl<Scalar> for Scalar {
399 /// type Output = Self;
401 /// fn shl(self, Self(rhs): Self) -> Self::Output {
402 /// let Self(lhs) = self;
407 /// assert_eq!(Scalar(4) << Scalar(2), Scalar(16));
410 /// An implementation of `Shl` that spins a vector leftward by a given amount.
413 /// use std::ops::Shl;
415 /// #[derive(PartialEq, Debug)]
416 /// struct SpinVector<T: Clone> {
420 /// impl<T: Clone> Shl<usize> for SpinVector<T> {
421 /// type Output = Self;
423 /// fn shl(self, rhs: usize) -> Self::Output {
424 /// // Rotate the vector by `rhs` places.
425 /// let (a, b) = self.vec.split_at(rhs);
426 /// let mut spun_vector = vec![];
427 /// spun_vector.extend_from_slice(b);
428 /// spun_vector.extend_from_slice(a);
429 /// Self { vec: spun_vector }
433 /// assert_eq!(SpinVector { vec: vec![0, 1, 2, 3, 4] } << 2,
434 /// SpinVector { vec: vec![2, 3, 4, 0, 1] });
438 #[stable(feature = "rust1", since = "1.0.0")]
439 #[rustc_on_unimplemented(
440 message
= "no implementation for `{Self} << {Rhs}`",
441 label
= "no implementation for `{Self} << {Rhs}`"
443 pub trait Shl
<Rhs
= Self> {
444 /// The resulting type after applying the `<<` operator.
445 #[stable(feature = "rust1", since = "1.0.0")]
448 /// Performs the `<<` operation.
453 /// assert_eq!(5u8 << 1, 10);
454 /// assert_eq!(1u8 << 1, 2);
457 #[stable(feature = "rust1", since = "1.0.0")]
458 fn shl(self, rhs
: Rhs
) -> Self::Output
;
461 macro_rules
! shl_impl
{
463 #[stable(feature = "rust1", since = "1.0.0")]
464 impl Shl
<$f
> for $t
{
468 #[rustc_inherit_overflow_checks]
469 fn shl(self, other
: $f
) -> $t
{
474 forward_ref_binop
! { impl Shl, shl for $t, $f }
478 macro_rules
! shl_impl_all
{
481 shl_impl
! { $t, u16 }
482 shl_impl
! { $t, u32 }
483 shl_impl
! { $t, u64 }
484 shl_impl
! { $t, u128 }
485 shl_impl
! { $t, usize }
488 shl_impl
! { $t, i16 }
489 shl_impl
! { $t, i32 }
490 shl_impl
! { $t, i64 }
491 shl_impl
! { $t, i128 }
492 shl_impl
! { $t, isize }
496 shl_impl_all
! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 isize i128 }
498 /// The right shift operator `>>`. Note that because this trait is implemented
499 /// for all integer types with multiple right-hand-side types, Rust's type
500 /// checker has special handling for `_ >> _`, setting the result type for
501 /// integer operations to the type of the left-hand-side operand. This means
502 /// that though `a >> b` and `a.shr(b)` are one and the same from an evaluation
503 /// standpoint, they are different when it comes to type inference.
507 /// An implementation of `Shr` that lifts the `>>` operation on integers to a
508 /// wrapper around `usize`.
511 /// use std::ops::Shr;
513 /// #[derive(PartialEq, Debug)]
514 /// struct Scalar(usize);
516 /// impl Shr<Scalar> for Scalar {
517 /// type Output = Self;
519 /// fn shr(self, Self(rhs): Self) -> Self::Output {
520 /// let Self(lhs) = self;
525 /// assert_eq!(Scalar(16) >> Scalar(2), Scalar(4));
528 /// An implementation of `Shr` that spins a vector rightward by a given amount.
531 /// use std::ops::Shr;
533 /// #[derive(PartialEq, Debug)]
534 /// struct SpinVector<T: Clone> {
538 /// impl<T: Clone> Shr<usize> for SpinVector<T> {
539 /// type Output = Self;
541 /// fn shr(self, rhs: usize) -> Self::Output {
542 /// // Rotate the vector by `rhs` places.
543 /// let (a, b) = self.vec.split_at(self.vec.len() - rhs);
544 /// let mut spun_vector = vec![];
545 /// spun_vector.extend_from_slice(b);
546 /// spun_vector.extend_from_slice(a);
547 /// Self { vec: spun_vector }
551 /// assert_eq!(SpinVector { vec: vec![0, 1, 2, 3, 4] } >> 2,
552 /// SpinVector { vec: vec![3, 4, 0, 1, 2] });
556 #[stable(feature = "rust1", since = "1.0.0")]
557 #[rustc_on_unimplemented(
558 message
= "no implementation for `{Self} >> {Rhs}`",
559 label
= "no implementation for `{Self} >> {Rhs}`"
561 pub trait Shr
<Rhs
= Self> {
562 /// The resulting type after applying the `>>` operator.
563 #[stable(feature = "rust1", since = "1.0.0")]
566 /// Performs the `>>` operation.
571 /// assert_eq!(5u8 >> 1, 2);
572 /// assert_eq!(2u8 >> 1, 1);
575 #[stable(feature = "rust1", since = "1.0.0")]
576 fn shr(self, rhs
: Rhs
) -> Self::Output
;
579 macro_rules
! shr_impl
{
581 #[stable(feature = "rust1", since = "1.0.0")]
582 impl Shr
<$f
> for $t
{
586 #[rustc_inherit_overflow_checks]
587 fn shr(self, other
: $f
) -> $t
{
592 forward_ref_binop
! { impl Shr, shr for $t, $f }
596 macro_rules
! shr_impl_all
{
599 shr_impl
! { $t, u16 }
600 shr_impl
! { $t, u32 }
601 shr_impl
! { $t, u64 }
602 shr_impl
! { $t, u128 }
603 shr_impl
! { $t, usize }
606 shr_impl
! { $t, i16 }
607 shr_impl
! { $t, i32 }
608 shr_impl
! { $t, i64 }
609 shr_impl
! { $t, i128 }
610 shr_impl
! { $t, isize }
614 shr_impl_all
! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
616 /// The bitwise AND assignment operator `&=`.
620 /// An implementation of `BitAndAssign` that lifts the `&=` operator to a
621 /// wrapper around `bool`.
624 /// use std::ops::BitAndAssign;
626 /// #[derive(Debug, PartialEq)]
627 /// struct Scalar(bool);
629 /// impl BitAndAssign for Scalar {
630 /// // rhs is the "right-hand side" of the expression `a &= b`
631 /// fn bitand_assign(&mut self, rhs: Self) {
632 /// *self = Self(self.0 & rhs.0)
636 /// let mut scalar = Scalar(true);
637 /// scalar &= Scalar(true);
638 /// assert_eq!(scalar, Scalar(true));
640 /// let mut scalar = Scalar(true);
641 /// scalar &= Scalar(false);
642 /// assert_eq!(scalar, Scalar(false));
644 /// let mut scalar = Scalar(false);
645 /// scalar &= Scalar(true);
646 /// assert_eq!(scalar, Scalar(false));
648 /// let mut scalar = Scalar(false);
649 /// scalar &= Scalar(false);
650 /// assert_eq!(scalar, Scalar(false));
653 /// Here, the `BitAndAssign` trait is implemented for a wrapper around
657 /// use std::ops::BitAndAssign;
659 /// #[derive(Debug, PartialEq)]
660 /// struct BooleanVector(Vec<bool>);
662 /// impl BitAndAssign for BooleanVector {
663 /// // `rhs` is the "right-hand side" of the expression `a &= b`.
664 /// fn bitand_assign(&mut self, rhs: Self) {
665 /// assert_eq!(self.0.len(), rhs.0.len());
669 /// .zip(rhs.0.iter())
670 /// .map(|(x, y)| *x & *y)
676 /// let mut bv = BooleanVector(vec![true, true, false, false]);
677 /// bv &= BooleanVector(vec![true, false, true, false]);
678 /// let expected = BooleanVector(vec![true, false, false, false]);
679 /// assert_eq!(bv, expected);
681 #[lang = "bitand_assign"]
683 #[stable(feature = "op_assign_traits", since = "1.8.0")]
684 #[rustc_on_unimplemented(
685 message
= "no implementation for `{Self} &= {Rhs}`",
686 label
= "no implementation for `{Self} &= {Rhs}`"
688 pub trait BitAndAssign
<Rhs
= Self> {
689 /// Performs the `&=` operation.
694 /// let mut x = true;
696 /// assert_eq!(x, false);
698 /// let mut x = true;
700 /// assert_eq!(x, true);
702 /// let mut x: u8 = 5;
704 /// assert_eq!(x, 1);
706 /// let mut x: u8 = 5;
708 /// assert_eq!(x, 0);
710 #[stable(feature = "op_assign_traits", since = "1.8.0")]
711 fn bitand_assign(&mut self, rhs
: Rhs
);
714 macro_rules
! bitand_assign_impl
{
716 #[stable(feature = "op_assign_traits", since = "1.8.0")]
717 impl BitAndAssign
for $t
{
719 fn bitand_assign(&mut self, other
: $t
) { *self &= other }
722 forward_ref_op_assign
! { impl BitAndAssign, bitand_assign for $t, $t }
726 bitand_assign_impl
! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
728 /// The bitwise OR assignment operator `|=`.
733 /// use std::ops::BitOrAssign;
735 /// #[derive(Debug, PartialEq)]
736 /// struct PersonalPreferences {
737 /// likes_cats: bool,
738 /// likes_dogs: bool,
741 /// impl BitOrAssign for PersonalPreferences {
742 /// fn bitor_assign(&mut self, rhs: Self) {
743 /// self.likes_cats |= rhs.likes_cats;
744 /// self.likes_dogs |= rhs.likes_dogs;
748 /// let mut prefs = PersonalPreferences { likes_cats: true, likes_dogs: false };
749 /// prefs |= PersonalPreferences { likes_cats: false, likes_dogs: true };
750 /// assert_eq!(prefs, PersonalPreferences { likes_cats: true, likes_dogs: true });
752 #[lang = "bitor_assign"]
754 #[stable(feature = "op_assign_traits", since = "1.8.0")]
755 #[rustc_on_unimplemented(
756 message
= "no implementation for `{Self} |= {Rhs}`",
757 label
= "no implementation for `{Self} |= {Rhs}`"
759 pub trait BitOrAssign
<Rhs
= Self> {
760 /// Performs the `|=` operation.
765 /// let mut x = true;
767 /// assert_eq!(x, true);
769 /// let mut x = false;
771 /// assert_eq!(x, false);
773 /// let mut x: u8 = 5;
775 /// assert_eq!(x, 5);
777 /// let mut x: u8 = 5;
779 /// assert_eq!(x, 7);
781 #[stable(feature = "op_assign_traits", since = "1.8.0")]
782 fn bitor_assign(&mut self, rhs
: Rhs
);
785 macro_rules
! bitor_assign_impl
{
787 #[stable(feature = "op_assign_traits", since = "1.8.0")]
788 impl BitOrAssign
for $t
{
790 fn bitor_assign(&mut self, other
: $t
) { *self |= other }
793 forward_ref_op_assign
! { impl BitOrAssign, bitor_assign for $t, $t }
797 bitor_assign_impl
! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
799 /// The bitwise XOR assignment operator `^=`.
804 /// use std::ops::BitXorAssign;
806 /// #[derive(Debug, PartialEq)]
807 /// struct Personality {
809 /// likes_knitting: bool,
812 /// impl BitXorAssign for Personality {
813 /// fn bitxor_assign(&mut self, rhs: Self) {
814 /// self.has_soul ^= rhs.has_soul;
815 /// self.likes_knitting ^= rhs.likes_knitting;
819 /// let mut personality = Personality { has_soul: false, likes_knitting: true };
820 /// personality ^= Personality { has_soul: true, likes_knitting: true };
821 /// assert_eq!(personality, Personality { has_soul: true, likes_knitting: false});
823 #[lang = "bitxor_assign"]
825 #[stable(feature = "op_assign_traits", since = "1.8.0")]
826 #[rustc_on_unimplemented(
827 message
= "no implementation for `{Self} ^= {Rhs}`",
828 label
= "no implementation for `{Self} ^= {Rhs}`"
830 pub trait BitXorAssign
<Rhs
= Self> {
831 /// Performs the `^=` operation.
836 /// let mut x = true;
838 /// assert_eq!(x, true);
840 /// let mut x = true;
842 /// assert_eq!(x, false);
844 /// let mut x: u8 = 5;
846 /// assert_eq!(x, 4);
848 /// let mut x: u8 = 5;
850 /// assert_eq!(x, 7);
852 #[stable(feature = "op_assign_traits", since = "1.8.0")]
853 fn bitxor_assign(&mut self, rhs
: Rhs
);
856 macro_rules
! bitxor_assign_impl
{
858 #[stable(feature = "op_assign_traits", since = "1.8.0")]
859 impl BitXorAssign
for $t
{
861 fn bitxor_assign(&mut self, other
: $t
) { *self ^= other }
864 forward_ref_op_assign
! { impl BitXorAssign, bitxor_assign for $t, $t }
868 bitxor_assign_impl
! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
870 /// The left shift assignment operator `<<=`.
874 /// An implementation of `ShlAssign` for a wrapper around `usize`.
877 /// use std::ops::ShlAssign;
879 /// #[derive(Debug, PartialEq)]
880 /// struct Scalar(usize);
882 /// impl ShlAssign<usize> for Scalar {
883 /// fn shl_assign(&mut self, rhs: usize) {
888 /// let mut scalar = Scalar(4);
890 /// assert_eq!(scalar, Scalar(16));
892 #[lang = "shl_assign"]
893 #[doc(alias = "<<=")]
894 #[stable(feature = "op_assign_traits", since = "1.8.0")]
895 #[rustc_on_unimplemented(
896 message
= "no implementation for `{Self} <<= {Rhs}`",
897 label
= "no implementation for `{Self} <<= {Rhs}`"
899 pub trait ShlAssign
<Rhs
= Self> {
900 /// Performs the `<<=` operation.
905 /// let mut x: u8 = 5;
907 /// assert_eq!(x, 10);
909 /// let mut x: u8 = 1;
911 /// assert_eq!(x, 2);
913 #[stable(feature = "op_assign_traits", since = "1.8.0")]
914 fn shl_assign(&mut self, rhs
: Rhs
);
917 macro_rules
! shl_assign_impl
{
919 #[stable(feature = "op_assign_traits", since = "1.8.0")]
920 impl ShlAssign
<$f
> for $t
{
922 #[rustc_inherit_overflow_checks]
923 fn shl_assign(&mut self, other
: $f
) {
928 forward_ref_op_assign
! { impl ShlAssign, shl_assign for $t, $f }
932 macro_rules
! shl_assign_impl_all
{
934 shl_assign_impl
! { $t, u8 }
935 shl_assign_impl
! { $t, u16 }
936 shl_assign_impl
! { $t, u32 }
937 shl_assign_impl
! { $t, u64 }
938 shl_assign_impl
! { $t, u128 }
939 shl_assign_impl
! { $t, usize }
941 shl_assign_impl
! { $t, i8 }
942 shl_assign_impl
! { $t, i16 }
943 shl_assign_impl
! { $t, i32 }
944 shl_assign_impl
! { $t, i64 }
945 shl_assign_impl
! { $t, i128 }
946 shl_assign_impl
! { $t, isize }
950 shl_assign_impl_all
! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
952 /// The right shift assignment operator `>>=`.
956 /// An implementation of `ShrAssign` for a wrapper around `usize`.
959 /// use std::ops::ShrAssign;
961 /// #[derive(Debug, PartialEq)]
962 /// struct Scalar(usize);
964 /// impl ShrAssign<usize> for Scalar {
965 /// fn shr_assign(&mut self, rhs: usize) {
970 /// let mut scalar = Scalar(16);
972 /// assert_eq!(scalar, Scalar(4));
974 #[lang = "shr_assign"]
975 #[doc(alias = ">>=")]
976 #[stable(feature = "op_assign_traits", since = "1.8.0")]
977 #[rustc_on_unimplemented(
978 message
= "no implementation for `{Self} >>= {Rhs}`",
979 label
= "no implementation for `{Self} >>= {Rhs}`"
981 pub trait ShrAssign
<Rhs
= Self> {
982 /// Performs the `>>=` operation.
987 /// let mut x: u8 = 5;
989 /// assert_eq!(x, 2);
991 /// let mut x: u8 = 2;
993 /// assert_eq!(x, 1);
995 #[stable(feature = "op_assign_traits", since = "1.8.0")]
996 fn shr_assign(&mut self, rhs
: Rhs
);
999 macro_rules
! shr_assign_impl
{
1001 #[stable(feature = "op_assign_traits", since = "1.8.0")]
1002 impl ShrAssign
<$f
> for $t
{
1004 #[rustc_inherit_overflow_checks]
1005 fn shr_assign(&mut self, other
: $f
) {
1010 forward_ref_op_assign
! { impl ShrAssign, shr_assign for $t, $f }
1014 macro_rules
! shr_assign_impl_all
{
1016 shr_assign_impl
! { $t, u8 }
1017 shr_assign_impl
! { $t, u16 }
1018 shr_assign_impl
! { $t, u32 }
1019 shr_assign_impl
! { $t, u64 }
1020 shr_assign_impl
! { $t, u128 }
1021 shr_assign_impl
! { $t, usize }
1023 shr_assign_impl
! { $t, i8 }
1024 shr_assign_impl
! { $t, i16 }
1025 shr_assign_impl
! { $t, i32 }
1026 shr_assign_impl
! { $t, i64 }
1027 shr_assign_impl
! { $t, i128 }
1028 shr_assign_impl
! { $t, isize }
1032 shr_assign_impl_all
! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }