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 @@ -538,26 +538,31 @@ neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 }
538
538
///
539
539
/// # Examples
540
540
///
541
- /// A trivial implementation of `Not`. When `!Foo` happens, it ends up calling
542
- /// `not`, and therefore, `main` prints `Not-ing!` .
541
+ /// An implementation of `Not` for `Answer`, which enables the use of `!` to
542
+ /// invert its value .
543
543
///
544
544
/// ```
545
545
/// use std::ops::Not;
546
546
///
547
- /// struct Foo;
547
+ /// #[derive(Debug, PartialEq)]
548
+ /// enum Answer {
549
+ /// Yes,
550
+ /// No,
551
+ /// }
548
552
///
549
- /// impl Not for Foo {
550
- /// type Output = Foo ;
553
+ /// impl Not for Answer {
554
+ /// type Output = Answer ;
551
555
///
552
- /// fn not(self) -> Foo {
553
- /// println!("Not-ing!");
554
- /// self
556
+ /// fn not(self) -> Answer {
557
+ /// match self {
558
+ /// Answer::Yes => Answer::No,
559
+ /// Answer::No => Answer::Yes
560
+ /// }
555
561
/// }
556
562
/// }
557
563
///
558
- /// fn main() {
559
- /// !Foo;
560
- /// }
564
+ /// assert_eq!(!Answer::Yes, Answer::No);
565
+ /// assert_eq!(!Answer::No, Answer::Yes);
561
566
/// ```
562
567
#[ lang = "not" ]
563
568
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments