Skip to content

Commit

Permalink
Rollup merge of rust-lang#35827 - matthew-piziak:neg-example, r=steve…
Browse files Browse the repository at this point in the history
…klabnik

replace `Not` example with something more evocative
  • Loading branch information
Jonathan Turner committed Aug 20, 2016
2 parents dddc485 + 06147ac commit 0090803
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 0090803

Please sign in to comment.