diff options
| author | Jonathan Turner <jonathandturner@users.noreply.github.com> | 2016-08-20 07:09:37 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-20 07:09:37 -0700 |
| commit | cc431a017d5c35e1376a33fb443c12e21d1139cc (patch) | |
| tree | bd0b5b9f4f70922fe037d6b5fc95ec224dde7e19 | |
| parent | f17ff3aa9370d38c6cfa7f1f118d70f856fc85e2 (diff) | |
| parent | 06147ac29152877830454330c16fd82f23d050df (diff) | |
| download | rust-cc431a017d5c35e1376a33fb443c12e21d1139cc.tar.gz rust-cc431a017d5c35e1376a33fb443c12e21d1139cc.zip | |
Rollup merge of #35827 - matthew-piziak:neg-example, r=steveklabnik
replace `Not` example with something more evocative
| -rw-r--r-- | src/libcore/ops.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 7c6776ebd1f..86439eca9e5 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -624,26 +624,31 @@ neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 } /// /// # Examples /// -/// A trivial implementation of `Not`. When `!Foo` happens, it ends up calling -/// `not`, and therefore, `main` prints `Not-ing!`. +/// An implementation of `Not` for `Answer`, which enables the use of `!` to +/// invert its value. /// /// ``` /// use std::ops::Not; /// -/// struct Foo; +/// #[derive(Debug, PartialEq)] +/// enum Answer { +/// Yes, +/// No, +/// } /// -/// impl Not for Foo { -/// type Output = Foo; +/// impl Not for Answer { +/// type Output = Answer; /// -/// fn not(self) -> Foo { -/// println!("Not-ing!"); -/// self +/// fn not(self) -> Answer { +/// match self { +/// Answer::Yes => Answer::No, +/// Answer::No => Answer::Yes +/// } /// } /// } /// -/// fn main() { -/// !Foo; -/// } +/// assert_eq!(!Answer::Yes, Answer::No); +/// assert_eq!(!Answer::No, Answer::Yes); /// ``` #[lang = "not"] #[stable(feature = "rust1", since = "1.0.0")] |
