File tree 1 file changed +16
-11
lines changed
1 file changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -624,26 +624,31 @@ neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 }
624
624
///
625
625
/// # Examples
626
626
///
627
- /// A trivial implementation of `Not`. When `!Foo` happens, it ends up calling
628
- /// `not`, and therefore, `main` prints `Not-ing!` .
627
+ /// An implementation of `Not` for `Answer`, which enables the use of `!` to
628
+ /// invert its value .
629
629
///
630
630
/// ```
631
631
/// use std::ops::Not;
632
632
///
633
- /// struct Foo;
633
+ /// #[derive(Debug, PartialEq)]
634
+ /// enum Answer {
635
+ /// Yes,
636
+ /// No,
637
+ /// }
634
638
///
635
- /// impl Not for Foo {
636
- /// type Output = Foo ;
639
+ /// impl Not for Answer {
640
+ /// type Output = Answer ;
637
641
///
638
- /// fn not(self) -> Foo {
639
- /// println!("Not-ing!");
640
- /// self
642
+ /// fn not(self) -> Answer {
643
+ /// match self {
644
+ /// Answer::Yes => Answer::No,
645
+ /// Answer::No => Answer::Yes
646
+ /// }
641
647
/// }
642
648
/// }
643
649
///
644
- /// fn main() {
645
- /// !Foo;
646
- /// }
650
+ /// assert_eq!(!Answer::Yes, Answer::No);
651
+ /// assert_eq!(!Answer::No, Answer::Yes);
647
652
/// ```
648
653
#[ lang = "not" ]
649
654
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments