Skip to content

Commit 06147ac

Browse files
replace Not example with something more evocative
1 parent 11f8805 commit 06147ac

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/libcore/ops.rs

+16-11
Original file line numberDiff line numberDiff 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")]

0 commit comments

Comments
 (0)