Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace Add example with something more evocative of addition #35709

Merged
merged 1 commit into from
Aug 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
//! }
//! ```
//!
//! See the documentation for each trait for a minimum implementation that
//! prints something to the screen.
//! See the documentation for each trait for an example implementation.

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down Expand Up @@ -166,25 +165,38 @@ macro_rules! forward_ref_binop {
///
/// # Examples
///
/// A trivial implementation of `Add`. When `Foo + Foo` happens, it ends up
/// calling `add`, and therefore, `main` prints `Adding!`.
/// This example creates a `Point` struct that implements the `Add` trait, and
/// then demonstrates adding two `Point`s.
///
/// ```
/// use std::ops::Add;
///
/// struct Foo;
/// #[derive(Debug)]
/// struct Point {
/// x: i32,
/// y: i32,
/// }
///
/// impl Add for Foo {
/// type Output = Foo;
/// impl Add for Point {
/// type Output = Point;
///
/// fn add(self, _rhs: Foo) -> Foo {
/// println!("Adding!");
/// self
/// fn add(self, other: Point) -> Point {
/// Point {
/// x: self.x + other.x,
/// y: self.y + other.y,
/// }
/// }
/// }
///
/// impl PartialEq for Point {
/// fn eq(&self, other: &Self) -> bool {
/// self.x == other.x && self.y == other.y
/// }
/// }
///
/// fn main() {
/// Foo + Foo;
/// assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
/// Point { x: 3, y: 3 });
/// }
/// ```
#[lang = "add"]
Expand Down