// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. #[feature(managed_boxes)]; use std::num::Zero; #[deriving(Zero)] struct Vector2(T, T); impl> Add, Vector2> for Vector2 { fn add(&self, other: &Vector2) -> Vector2 { match (self, other) { (&Vector2(ref x0, ref y0), &Vector2(ref x1, ref y1)) => { Vector2(*x0 + *x1, *y0 + *y1) } } } } #[deriving(Zero)] struct Vector3 { x: T, y: T, z: T, } impl> Add, Vector3> for Vector3 { fn add(&self, other: &Vector3) -> Vector3 { Vector3 { x: self.x + other.x, y: self.y + other.y, z: self.z + other.z, } } } #[deriving(Zero)] struct Matrix3x2 { x: Vector2, y: Vector2, z: Vector2, } impl> Add, Matrix3x2> for Matrix3x2 { fn add(&self, other: &Matrix3x2) -> Matrix3x2 { Matrix3x2 { x: self.x + other.x, y: self.y + other.y, z: self.z + other.z, } } } pub fn main() { let _: Vector2 = Zero::zero(); let _: Vector3 = Zero::zero(); let _: Matrix3x2 = Zero::zero(); }