Skip to content

Commit cc431a0

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35827 - matthew-piziak:neg-example, r=steveklabnik
replace `Not` example with something more evocative
2 parents f17ff3a + 06147ac commit cc431a0

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/libcore/ops.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff 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")]

0 commit comments

Comments
 (0)