Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Overloaded binary '+' operator
- impl<T> Add for Vector<T> where T: Copy + fmt::Display + num::Num {
- type Output = Vector<T>;
- fn add(self: Vector<T>, other: Vector<T>) -> Vector<T> {
- if self.vec.len() != other.vec.len() {
- panic!("The length of the two vectors are unequal");
- }
- let mut v: Vec<T> = Vec::new();
- for i in 0..(self.vec.len()) {
- v.push(self.vec[i] + other.vec[i]);
- }
- Vector{ vec: v }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement