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 @@ -538,26 +538,31 @@ neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 }
538538///
539539/// # Examples
540540///
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 .
543543///
544544/// ```
545545/// use std::ops::Not;
546546///
547- /// struct Foo;
547+ /// #[derive(Debug, PartialEq)]
548+ /// enum Answer {
549+ /// Yes,
550+ /// No,
551+ /// }
548552///
549- /// impl Not for Foo {
550- /// type Output = Foo ;
553+ /// impl Not for Answer {
554+ /// type Output = Answer ;
551555///
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+ /// }
555561/// }
556562/// }
557563///
558- /// fn main() {
559- /// !Foo;
560- /// }
564+ /// assert_eq!(!Answer::Yes, Answer::No);
565+ /// assert_eq!(!Answer::No, Answer::Yes);
561566/// ```
562567#[ lang = "not" ]
563568#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments