1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test that we can overload the `+` operator for points so that two
12 // points can be added, and a point can be added to an integer.
16 #[derive(Debug,PartialEq,Eq)]
22 impl ops
::Add
for Point
{
25 fn add(self, other
: Point
) -> Point
{
26 Point {x: self.x + other.x, y: self.y + other.y}
30 impl ops
::Add
<isize> for Point
{
33 fn add(self, other
: isize) -> Point
{
34 Point
{x
: self.x
+ other
,
40 let mut p
= Point {x: 10, y: 20}
;
41 p
= p
+ Point {x: 101, y: 102}
;
42 assert_eq
!(p
, Point {x: 111, y: 122}
);
44 assert_eq
!(p
, Point {x: 112, y: 123}
);