File tree Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Expand file tree Collapse file tree 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 }
624624///
625625/// # Examples
626626///
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 .
629629///
630630/// ```
631631/// use std::ops::Not;
632632///
633- /// struct Foo;
633+ /// #[derive(Debug, PartialEq)]
634+ /// enum Answer {
635+ /// Yes,
636+ /// No,
637+ /// }
634638///
635- /// impl Not for Foo {
636- /// type Output = Foo ;
639+ /// impl Not for Answer {
640+ /// type Output = Answer ;
637641///
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+ /// }
641647/// }
642648/// }
643649///
644- /// fn main() {
645- /// !Foo;
646- /// }
650+ /// assert_eq!(!Answer::Yes, Answer::No);
651+ /// assert_eq!(!Answer::No, Answer::Yes);
647652/// ```
648653#[ lang = "not" ]
649654#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments