Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::{Add, Mul, Div, Sub};
- fn main() {
- let a = &(&Vec3 { x: 10.0, y: 20.0, z: 30.0 } + 5.0) * 2.0;
- assert_eq!(a, Vec3 { x: 30.0, y: 50.0, z: 70.0 });
- }
- #[derive(Debug, PartialEq)]
- struct Vec3 {
- x: f32,
- y: f32,
- z: f32,
- }
- macro_rules! impl_for_ref {
- ( $trait:ty, $other:ty, $method:ident, $symb:tt ) => {
- impl $trait for &Vec3 {
- type Output = Vec3;
- fn $method(self, other: $other) -> Vec3 {
- Vec3 {
- x: self.x $symb other,
- y: self.y $symb other,
- z: self.z $symb other,
- }
- }
- }
- };
- }
- impl_for_ref!(Add<f32>, f32, add, +);
- impl_for_ref!(Mul<f32>, f32, mul, *);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement