```#[lang = "add"]
pub trait Add<RHS = Self> {
type Output;
#[must_use]
fn add(self, rhs: RHS) -> Self::Output;
}```

The addition operator `+`.

Note that `RHS` is `Self` by default, but this is not mandatory. For example, `std::time::SystemTime` implements `Add<Duration>`, which permits operations of the form `SystemTime = SystemTime + Duration`.

# Examples

## `Add`able points

```use std::ops::Add;

#[derive(Debug, PartialEq)]
struct Point {
x: i32,
y: i32,
}

type Output = Point;

fn add(self, other: Point) -> Point {
Point {
x: self.x + other.x,
y: self.y + other.y,
}
}
}

assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
Point { x: 3, y: 3 });Run```

## Implementing `Add` with generics

Here is an example of the same `Point` struct implementing the `Add` trait using generics.

```use std::ops::Add;

#[derive(Debug, PartialEq)]
struct Point<T> {
x: T,
y: T,
}

// Notice that the implementation uses the associated type `Output`.
type Output = Point<T>;

fn add(self, other: Point<T>) -> Point<T> {
Point {
x: self.x + other.x,
y: self.y + other.y,
}
}
}

assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
Point { x: 3, y: 3 });Run```

## Associated Types

### `type Output`

The resulting type after applying the `+` operator.

## Required Methods

### ```#[must_use] fn add(self, rhs: RHS) -> Self::Output```

Performs the `+` operation.

## Implementors

### `impl<'a> Add<&'a str> for String`[src]

Implements the `+` operator for concatenating two strings.

This consumes the `String` on the left-hand side and re-uses its buffer (growing it if necessary). This is done to avoid allocating a new `String` and copying the entire contents on every operation, which would lead to `O(n^2)` running time when building an `n`-byte string by repeated concatenation.

The string on the right-hand side is only borrowed; its contents are copied into the returned `String`.

# Examples

Concatenating two `String`s takes the first by value and borrows the second:

```let a = String::from("hello");
let b = String::from(" world");
let c = a + &b;
// `a` is moved and can no longer be used here.Run```

If you want to keep using the first `String`, you can clone it and append to the clone instead:

```let a = String::from("hello");
let b = String::from(" world");
let c = a.clone() + &b;
// `a` is still valid here.Run```

Concatenating `&str` slices can be done by converting the first to a `String`:

```let a = "hello";
let b = " world";
let c = a.to_string() + b;Run```