ops-derive 0.1.1

Derive macros for std::ops
Documentation
use ops_derive::*;

#[derive(
    Copy,
    Clone,
    PartialEq,
    Debug,
	AutoAll,
    // AutoAdd,
    // AutoSub,
    // AutoMul,
    // AutoDiv,
    // AutoNeg,
    // AutoAddAssign,
    // AutoDivAssign,
    // AutoMulAssign,
    // AutoSubAssign,
)]
pub struct Point {
    x: f32,
    y: f32,
    z: f32,
}

impl Point {
    fn new(x: f32, y: f32, z: f32) -> Self {
        Self { x, y, z }
    }
}

#[test]
fn base() {
    let a = Point::new(1.0, 2.0, 3.0);
    let b = Point::new(4.0, 5.0, 6.0);

    let add = Point::new(5.0, 7.0, 9.0);
    let sub = Point::new(-3.0, -3.0, -3.0);
    let mul = Point::new(4.0, 10.0, 18.0);
    let div = Point::new(0.25, 0.4, 0.5);

    let neg = Point::new(-1.0, -2.0, -3.0);

    assert_eq!(a + b, add);
    assert_eq!(a - b, sub);
    assert_eq!(a * b, mul);
    assert_eq!(a / b, div);
    assert_eq!(-a, neg);
}

macro_rules! assert_assign {
	($a:ident $op:tt $b:ident = $out:ident) => {
		{
			let mut actual = $a.clone();
			actual $op $b;
			assert_eq!(actual, $out)
		}
	};
}

#[test]
fn assign() {
    let a = Point::new(1.0, 2.0, 3.0);
    let b = Point::new(4.0, 5.0, 6.0);

    let add = Point::new(5.0, 7.0, 9.0);
    let sub = Point::new(-3.0, -3.0, -3.0);
    let mul = Point::new(4.0, 10.0, 18.0);
    let div = Point::new(0.25, 0.4, 0.5);

    assert_assign!(a += b = add);
    assert_assign!(a -= b = sub);
    assert_assign!(a *= b = mul);
    assert_assign!(a /= b = div);
}